Implementar Issues #2-4, #8-13, #16 - Funcionalidades core del tema
Implementación masiva de funcionalidades esenciales del tema apus-theme usando agentes paralelos para máxima eficiencia. **Issues Completados:** **Issue #2 - Eliminar bloat de WordPress:** - inc/performance.php: 13 funciones que remueven emojis, oEmbed, feeds, dashicons, jQuery migrate, XML-RPC, etc. - Optimización completa del frontend **Issue #3 - Desactivar búsqueda nativa:** - inc/search-disable.php: Bloquea queries de búsqueda, widget, formularios - search.php: Retorna 404 con mensaje amigable **Issue #4 - Desactivar comentarios:** - inc/comments-disable.php: 15 funciones que eliminan comentarios de frontend y backend - comments.php: Template desactivado **Issue #8 - Footer con 4 widgets:** - footer.php: Verificado con 4 áreas de widgets y copyright - assets/css/footer.css: Estilos responsive completos - Sistema de anchos configurables **Issue #9 - Jerarquía de plantillas:** - home.php, category.php, tag.php, author.php, date.php, taxonomy.php, attachment.php - 7 nuevas plantillas + 12 verificadas - Template parts completos - Paginación en todos los archives **Issue #10 - Imágenes destacadas:** - inc/featured-image.php: 12 funciones para manejo de featured images - Sin placeholders, lazy loading, alt text automático - Responsive con Bootstrap, aspect ratio **Issue #11 - Badge de categoría:** - inc/category-badge.php: Badge Bootstrap sobre H1 en single posts - Excluye "Uncategorized" - Template tag: apus_display_category_badge() **Issue #12 - TOC automático:** - inc/toc.php: Genera TOC desde H2/H3 - assets/css/toc.css: Estilos con numeración CSS counters - assets/js/toc.js: Smooth scroll, scroll spy, toggle - Configurable con apus_get_option() **Issue #13 - Posts relacionados:** - inc/related-posts.php: Query por categoría, 12 funciones - inc/admin/related-posts-options.php: Sistema de configuración - assets/css/related-posts.css: Cards responsive - Hook automático en single posts **Issue #16 - AdSense delay:** - inc/adsense-delay.php: Retardo de carga hasta scroll/click - assets/js/adsense-loader.js: Detecta interacciones - Mejora FID y TBT para Core Web Vitals **Archivos Modificados:** - functions.php: Includes de nuevos módulos, removido feed support - single.php: Integración de category badge - inc/enqueue-scripts.php: Enqueue de nuevos assets - inc/theme-options-helpers.php: Helper functions para TOC **Archivos Creados:** - 7 nuevas plantillas WordPress - 3 nuevos módulos inc/ (comments-disable, search-disable) - 8 reportes de documentación .md **Estadísticas:** - Total funciones PHP: 60+ nuevas funciones - Líneas de código: 2,500+ líneas - Archivos nuevos: 18 - Archivos modificados: 9 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -15,74 +15,74 @@ if (!defined('ABSPATH')) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay AdSense scripts by intercepting output buffer
|
||||
* Retarda la carga de scripts de AdSense interceptando el buffer de salida
|
||||
*
|
||||
* This function starts output buffering and replaces AdSense scripts
|
||||
* with delayed versions when the page is rendered.
|
||||
* Esta función inicia el output buffering y reemplaza los scripts de AdSense
|
||||
* con versiones retrasadas cuando se renderiza la página.
|
||||
*/
|
||||
function apus_delay_adsense_scripts() {
|
||||
// Only run on frontend
|
||||
// Solo ejecutar en frontend
|
||||
if (is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if AdSense delay is enabled in theme options
|
||||
$delay_enabled = get_theme_mod('apus_adsense_delay_enabled', true);
|
||||
// Verificar si el retardo de AdSense está habilitado en las opciones del tema
|
||||
$delay_enabled = apus_get_option('apus_adsense_delay_enabled', '1');
|
||||
|
||||
if (!$delay_enabled) {
|
||||
if ($delay_enabled !== '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start output buffering
|
||||
// Iniciar output buffering
|
||||
ob_start('apus_replace_adsense_scripts');
|
||||
}
|
||||
add_action('template_redirect', 'apus_delay_adsense_scripts', 1);
|
||||
|
||||
/**
|
||||
* Replace AdSense scripts with delayed versions
|
||||
* Reemplaza scripts de AdSense con versiones retrasadas
|
||||
*
|
||||
* This function processes the HTML output and replaces standard AdSense
|
||||
* script tags with delayed loading versions.
|
||||
* Esta función procesa la salida HTML y reemplaza las etiquetas de script
|
||||
* estándar de AdSense con versiones de carga retrasada.
|
||||
*
|
||||
* @param string $html The HTML content to process
|
||||
* @return string Modified HTML with delayed AdSense scripts
|
||||
* @param string $html El contenido HTML a procesar
|
||||
* @return string HTML modificado con scripts de AdSense retrasados
|
||||
*/
|
||||
function apus_replace_adsense_scripts($html) {
|
||||
// Only process if there's actual AdSense content
|
||||
// Solo procesar si hay contenido real de AdSense
|
||||
if (strpos($html, 'pagead2.googlesyndication.com') === false &&
|
||||
strpos($html, 'adsbygoogle.js') === false) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
// Pattern to match AdSense script tags
|
||||
// Patrones para encontrar etiquetas de script de AdSense
|
||||
$patterns = array(
|
||||
// Match async script tags for AdSense
|
||||
// Buscar etiquetas de script async para AdSense
|
||||
'/<script\s+async\s+src=["\']https:\/\/pagead2\.googlesyndication\.com\/pagead\/js\/adsbygoogle\.js[^"\']*["\']\s*(?:crossorigin=["\']anonymous["\'])?\s*><\/script>/i',
|
||||
|
||||
// Match script tags without async
|
||||
// Buscar etiquetas de script sin async
|
||||
'/<script\s+src=["\']https:\/\/pagead2\.googlesyndication\.com\/pagead\/js\/adsbygoogle\.js[^"\']*["\']\s*(?:crossorigin=["\']anonymous["\'])?\s*><\/script>/i',
|
||||
|
||||
// Match inline adsbygoogle.push scripts
|
||||
// Buscar scripts inline de adsbygoogle.push
|
||||
'/<script>\s*\(adsbygoogle\s*=\s*window\.adsbygoogle\s*\|\|\s*\[\]\)\.push\(\{[^}]*\}\);\s*<\/script>/is',
|
||||
);
|
||||
|
||||
// Replace async AdSense scripts with delayed versions
|
||||
// Reemplazar scripts async de AdSense con versiones retrasadas
|
||||
$replacements = array(
|
||||
// Replace async script tag with data attribute for delayed loading
|
||||
// Reemplazar etiqueta de script async con atributo data para carga retrasada
|
||||
'<script type="text/plain" data-adsense-script src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" crossorigin="anonymous"></script>',
|
||||
|
||||
// Replace non-async script tag
|
||||
// Reemplazar etiqueta de script no-async
|
||||
'<script type="text/plain" data-adsense-script src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" crossorigin="anonymous"></script>',
|
||||
|
||||
// Replace inline push scripts with delayed versions
|
||||
// Reemplazar scripts de push inline con versiones retrasadas
|
||||
'<script type="text/plain" data-adsense-push>$0</script>',
|
||||
);
|
||||
|
||||
// First pass: replace script tags
|
||||
// Primera pasada: reemplazar etiquetas de script
|
||||
$html = preg_replace($patterns[0], $replacements[0], $html);
|
||||
$html = preg_replace($patterns[1], $replacements[1], $html);
|
||||
|
||||
// Second pass: replace inline push calls
|
||||
// Segunda pasada: reemplazar llamadas inline de push
|
||||
$html = preg_replace_callback(
|
||||
'/<script>\s*\(adsbygoogle\s*=\s*window\.adsbygoogle\s*\|\|\s*\[\]\)\.push\(\{[^}]*\}\);\s*<\/script>/is',
|
||||
function($matches) {
|
||||
@@ -91,30 +91,30 @@ function apus_replace_adsense_scripts($html) {
|
||||
$html
|
||||
);
|
||||
|
||||
// Add a comment to indicate processing occurred
|
||||
// Agregar comentario para indicar que se procesó (solo en modo debug)
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
$html = str_replace('</body>', '<!-- AdSense scripts delayed by Apus Theme --></body>', $html);
|
||||
$html = str_replace('</body>', '<!-- Scripts de AdSense retrasados por Apus Theme --></body>', $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add inline script to initialize delayed AdSense
|
||||
* Agrega script inline para inicializar AdSense retrasado
|
||||
*
|
||||
* This adds a small inline script that marks AdSense as ready to load
|
||||
* after the adsense-loader.js has been enqueued.
|
||||
* Esto agrega un pequeño script inline que marca AdSense como listo para cargar
|
||||
* después de que adsense-loader.js ha sido enqueued.
|
||||
*/
|
||||
function apus_add_adsense_init_script() {
|
||||
$delay_enabled = get_theme_mod('apus_adsense_delay_enabled', true);
|
||||
$delay_enabled = apus_get_option('apus_adsense_delay_enabled', '1');
|
||||
|
||||
if (!$delay_enabled || is_admin()) {
|
||||
if ($delay_enabled !== '1' || is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<script>
|
||||
// Initialize AdSense delay flag
|
||||
// Inicializar flag de retardo de AdSense
|
||||
window.apusAdsenseDelayed = true;
|
||||
</script>
|
||||
<?php
|
||||
@@ -122,33 +122,29 @@ function apus_add_adsense_init_script() {
|
||||
add_action('wp_head', 'apus_add_adsense_init_script', 1);
|
||||
|
||||
/**
|
||||
* Register customizer settings for AdSense delay
|
||||
* INSTRUCCIONES DE USO:
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object
|
||||
* Para activar el retardo de carga de AdSense:
|
||||
* 1. Ir al panel de opciones del tema (Dashboard > Apus Theme Options)
|
||||
* 2. En la sección "Performance", activar la opción "Delay AdSense Loading"
|
||||
* 3. Guardar cambios
|
||||
*
|
||||
* Comportamiento:
|
||||
* - Los scripts de AdSense NO se cargarán hasta que el usuario:
|
||||
* * Haga scroll en la página
|
||||
* * Haga click en cualquier parte
|
||||
* * Toque la pantalla (móviles)
|
||||
* * Mueva el mouse
|
||||
* * Presione una tecla
|
||||
* - Si no hay interacción, los scripts se cargarán después de 5 segundos
|
||||
*
|
||||
* Beneficios:
|
||||
* - Mejora significativa en Core Web Vitals (FID, TBT)
|
||||
* - Reduce el tiempo de carga inicial de la página
|
||||
* - No afecta la monetización (los ads se siguen mostrando)
|
||||
* - Sin layout shifts al cargar los ads
|
||||
*
|
||||
* Para desactivar:
|
||||
* - Desmarcar la opción en el panel de opciones del tema
|
||||
* - Los scripts de AdSense se cargarán normalmente
|
||||
*/
|
||||
function apus_adsense_delay_customizer($wp_customize) {
|
||||
// Add Performance section if it doesn't exist
|
||||
if (!$wp_customize->get_section('apus_performance')) {
|
||||
$wp_customize->add_section('apus_performance', array(
|
||||
'title' => __('Performance Settings', 'apus-theme'),
|
||||
'priority' => 130,
|
||||
));
|
||||
}
|
||||
|
||||
// Add setting for AdSense delay
|
||||
$wp_customize->add_setting('apus_adsense_delay_enabled', array(
|
||||
'default' => true,
|
||||
'sanitize_callback' => 'apus_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
// Add control for AdSense delay
|
||||
$wp_customize->add_control('apus_adsense_delay_enabled', array(
|
||||
'label' => __('Delay AdSense Loading', 'apus-theme'),
|
||||
'description' => __('Delay AdSense scripts until user interaction to improve page load speed.', 'apus-theme'),
|
||||
'section' => 'apus_performance',
|
||||
'type' => 'checkbox',
|
||||
));
|
||||
}
|
||||
add_action('customize_register', 'apus_adsense_delay_customizer');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user