WordPress Optimization - Skill
Descripción
Optimiza WordPress 6.9 para performance, SEO y accesibilidad. Incluye caché, CDN setup, Core Web Vitals y análisis de rendimiento.
Cuándo usar
code
"Optimiza WordPress" "Mejora Core Web Vitals" "Acelera el sitio" "Optimiza imágenes en WordPress" "Mejora SEO del sitio"
Flujo de Ejecución
Pre-Analysis (Diagnóstico)
bash
# 1. Verificar versión WordPress wp core version --allow-root # 2. Verificar plugins activos y versiones wp plugin list --allow-root | grep -E "active|inactive" # 3. Revisar theme activo wp theme list --allow-root --field=name,status | grep active # 4. Revisar tamaño de BD wp db query "SELECT ROUND(SUM(data_length+index_length)/1024/1024) AS size FROM information_schema.tables WHERE table_schema=DATABASE();" --skip-column-names # 5. Check WP Config grep -E "WP_MEMORY_LIMIT|WP_DEBUG|DISALLOW_FILE_EDIT" wp-config.php
Optimization Layer 1: Caching
Object Cache
php
// Objetivo: Reducir consultas a BD en 80%+ // Implementación: Redis o Memcached // 1. Instalar plugin wp plugin install redis-cache --activate --allow-root // 2. Enable Redis wp redis enable --allow-root // 3. Verify wp redis status --allow-root // Resultado esperado: // - Homepage load time: 2.5s → 0.8s // - Database queries: 89 → 12
Page Cache
php
// Objetivo: Servir HTML estático (sin ejecutar PHP)
// Implementación: WP Super Cache o W3 Total Cache
// 1. Instalar
wp plugin install wp-super-cache --activate --allow-root
// 2. Configure
wp super-cache flush --allow-root
wp super-cache enable --allow-root
// 3. Settings
define('WP_CACHE', true);
// Resultado:
// - Time to First Byte (TTFB): 1.2s → 0.15s
Database Optimization
bash
# 1. Limpiar tablas huérfanas wp db clean all --allow-root # 2. Optimizar tablas wp db optimize --allow-root # 3. Eliminar revisions viejas (guardar últimas 5) wp post delete --post_type='revision' --force --all --allow-root # 4. Limpiar post meta huérfana wp db query " DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts p ON p.ID = pm.post_id WHERE p.ID IS NULL; " --allow-root # Resultado: # - DB size: 450MB → 250MB (44% reducción)
Optimization Layer 2: Images & Media
Lazy Loading
php
// Objetivo: Solo cargar imágenes visibles en viewport
// WP 6.9 soporte nativo
// En functions.php:
add_filter('wp_img_tag_add_loading_attr', '__return_true');
// Resultado:
// - Payload inicial: 8.5MB → 2.3MB
// - LCP (Largest Contentful Paint): 3.2s → 1.8s
Image Optimization (WebP/AVIF)
bash
# 1. Activar WebP automático wp plugin install shortpixel-image-optimiser --activate --allow-root # 2. O usar RunMedia (custom) cd /home/pepe/runart-foundry python apps/runmedia/main.py optimize --format webp,avif \ --input wp-content/uploads/ \ --quality 82 # 3. Verificar ls wp-content/uploads/2024/01/ | grep -E "webp|avif" | wc -l # Resultado: # - JPEG: 450 archivos # - WebP: 450 archivos (35% más pequeño) # - AVIF: 450 archivos (25% más pequeño que WebP)
CDN Setup
bash
# Objetivo: Servir assets desde ubicación geográfica cercana # Usar CloudFlare o IONOS CDN # 1. Verificar DNS de RunArt dig runartfoundry.com +short # 2. Configurar CNAME en IONOS dashboard # www.runartfoundry.com CNAME cdn.runartfoundry.com # 3. En WP, agregar URL de CDN wp option update home 'https://runartfoundry.com' --allow-root wp option update siteurl 'https://runartfoundry.com' --allow-root # 4. Plugin para reescribir URLs wp plugin install cdn-enabler --activate --allow-root # Resultado: # - Latencia global: 250ms → 80ms (5-10 geos)
Optimization Layer 3: Code & Resources
Critical CSS
bash
# Objetivo: Inline CSS crítico para mejorar FCP (First Contentful Paint)
# 1. Identificar CSS crítico (critical path)
wp plugin install critical-css-optimizer --activate --allow-root
# 2. O manual: agregar en wp_head
add_action('wp_head', function() {
echo '<style>' . file_get_contents('critical.css') . '</style>';
});
# Resultado:
# - FCP: 2.1s → 0.9s
Minification & Compression
php
// 1. Habilitar Gzip (en .htaccess) # <IfModule mod_deflate.c> # AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript # </IfModule> // 2. Plugin para minification wp plugin install autoptimize --activate --allow-root // 3. Configure wp option update autoptimize_html 'on' --allow-root wp option update autoptimize_js 'on' --allow-root wp option update autoptimize_css 'on' --allow-root // Resultado: // - Tamaño JS: 850KB → 240KB (71% reducción) // - Tamaño CSS: 340KB → 95KB (72% reducción)
Optimization Layer 4: SEO & Core Web Vitals
Measure Performance
bash
# 1. Lighthouse CLI npm install -g @lhci/cli lhci autorun --config lighthouserc.json # 2. Verificar Core Web Vitals # - LCP (Largest Contentful Paint): < 2.5s ✅ # - FID (First Input Delay): < 100ms ✅ # - CLS (Cumulative Layout Shift): < 0.1 ✅
SEO Best Practices
php
// 1. XML Sitemap
wp plugin install yoast-seo --activate --allow-root
// 2. Meta tags
wp option update blogdescription 'RunArt Foundry - Escultura y Fundición' --allow-root
// 3. Structured Data (JSON-LD)
add_action('wp_head', function() {
echo '<script type="application/ld+json">' . json_encode([
"@context" => "https://schema.org",
"@type" => "LocalBusiness",
"name" => "RunArt Foundry",
"url" => "https://runartfoundry.com",
"description" => "Taller de escultura y fundición"
]) . '</script>';
});
// Resultado:
// - SEO score: 72 → 94
// - Rich snippets en SERP
Monitoring & Alerts
bash
# 1. Instalar monitoring wp plugin install health-check --activate --allow-root # 2. Setup email alerts wp cron test --allow-root # 3. Verificar logs tail -100 /home/pepe/runart-foundry/wp-content/debug.log | grep -E "ERROR|WARNING"
Performance Target Metrics
| Métrica | Antes | Después | Meta |
|---|---|---|---|
| Tamaño página | 8.2 MB | 2.1 MB | < 3 MB ✅ |
| TTFB | 1.8s | 0.3s | < 0.6s ✅ |
| LCP | 3.2s | 1.5s | < 2.5s ✅ |
| Queries BD | 89 | 12 | < 20 ✅ |
| Lighthouse | 42 | 92 | > 90 ✅ |
| SEO Score | 72 | 94 | > 85 ✅ |
Implementación por Prioridad
Priority 1: Caching (Impacto 60%)
bash
□ Object Cache (Redis) □ Page Cache (WP Super Cache) □ DB Optimization □ Verificar métricas
Tiempo: 1-2 horas
Impacto: +70% velocidad
Priority 2: Images (Impacto 20%)
bash
□ Lazy loading □ WebP/AVIF conversion □ CDN setup □ Verificar Assets
Tiempo: 1-2 horas
Impacto: +40% velocidad, -60% bandwidth
Priority 3: Code (Impacto 15%)
bash
□ Minification □ Critical CSS □ Gzip compression □ Inline resources
Tiempo: 1 hora
Impacto: +20% velocidad
Priority 4: Monitoring (Impacto 5%)
bash
□ Performance monitoring □ Error tracking □ Health checks □ Alerts
Tiempo: 30 min
Impacto: Prevención de issues
Rollback Plan
Si algo falla después de optimización:
bash
# 1. Desactivar plugin problemático wp plugin deactivate plugin-name --allow-root # 2. Restaurar desde backup tar -xzf ../backups/wp-content-before-optimization.tar.gz # 3. Verificar WordPress wp health-check status --allow-root # 4. Verificar logs tail -50 wp-content/debug.log
Validación Final
bash
□ TTFB < 0.6s □ LCP < 2.5s (Core Web Vitals green) □ Lighthouse > 90 □ SEO score > 85 □ No broken images □ No 404 errors □ Plugins activos = los esperados □ BD íntegra (wp health-check) □ Backups creados ANTES de cambios
Documentación
Métricas de Éxito
- •Velocidad: 50-70% más rápido
- •SEO: +20 puntos score
- •Bandwidth: -50% (con WebP/AVIF)
- •Uptime: 99.9%+