refactor(adsense): remove dead code + PageSpeed CSS defer
- Remove unused roi_should_disable_auto_ads() function - Remove enable_page_level_ads code (Auto Ads disabled in Google panel) - Defer non-critical CSS with media=print pattern (Fase 4.2 PageSpeed) - Fix roi-accessibility dependency: roi-theme-style -> roi-main-style 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,56 @@ if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS no críticos que se cargarán de forma diferida (Fase 4.2 PageSpeed)
|
||||
*
|
||||
* Estos CSS se cargan con media="print" y onload="this.media='all'"
|
||||
* para evitar bloquear el renderizado inicial.
|
||||
*
|
||||
* @since 1.0.21
|
||||
*/
|
||||
define('ROI_DEFERRED_CSS', [
|
||||
'roi-badges',
|
||||
'roi-pagination',
|
||||
'roi-generic-tables',
|
||||
'roi-video',
|
||||
'roi-animations',
|
||||
'roi-youtube-facade',
|
||||
'roi-tables-apu',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Add async loading to deferred stylesheets (Fase 4.2 PageSpeed)
|
||||
*
|
||||
* Converts media="print" to media="all" after load to prevent render-blocking.
|
||||
*
|
||||
* @since 1.0.21
|
||||
* @param string $html The link tag HTML.
|
||||
* @param string $handle The stylesheet handle.
|
||||
* @return string Modified link tag.
|
||||
*/
|
||||
function roi_add_deferred_css_onload($html, $handle) {
|
||||
if (!in_array($handle, ROI_DEFERRED_CSS, true)) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
// Add onload attribute to switch media to "all" after load
|
||||
$html = str_replace(
|
||||
"media='print'",
|
||||
"media='print' onload=\"this.media='all'\"",
|
||||
$html
|
||||
);
|
||||
|
||||
// Add noscript fallback for users without JavaScript
|
||||
$href = preg_match('/href=[\'"]([^\'"]+)[\'"]/', $html, $matches) ? $matches[1] : '';
|
||||
if ($href) {
|
||||
$html .= '<noscript><link rel="stylesheet" href="' . esc_url($href) . '"></noscript>' . "\n";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
add_filter('style_loader_tag', 'roi_add_deferred_css_onload', 10, 2);
|
||||
|
||||
/**
|
||||
* Enqueue typography system
|
||||
*
|
||||
@@ -113,21 +163,23 @@ function roi_enqueue_fase2_styles() {
|
||||
// @see Public/Hero/Infrastructure/Ui/HeroRenderer.php
|
||||
|
||||
// Category Badges CSS - Clase genérica (Issue #62)
|
||||
// DIFERIDO: Fase 4.2 PageSpeed - media='print' + onload
|
||||
wp_enqueue_style(
|
||||
'roi-badges',
|
||||
get_template_directory_uri() . '/Assets/css/css-global-badges.css',
|
||||
array('roi-bootstrap'),
|
||||
filemtime(get_template_directory() . '/Assets/css/css-global-badges.css'),
|
||||
'all'
|
||||
'print' // Diferido para no bloquear renderizado
|
||||
);
|
||||
|
||||
// Pagination CSS - Estilos personalizados (Issue #64)
|
||||
// DIFERIDO: Fase 4.2 PageSpeed - below the fold
|
||||
wp_enqueue_style(
|
||||
'roi-pagination',
|
||||
get_template_directory_uri() . '/Assets/css/css-global-pagination.css',
|
||||
array('roi-bootstrap'),
|
||||
filemtime(get_template_directory() . '/Assets/css/css-global-pagination.css'),
|
||||
'all'
|
||||
'print' // Diferido para no bloquear renderizado
|
||||
);
|
||||
|
||||
// Post Content Typography y Related Posts - DESHABILITADOS
|
||||
@@ -232,12 +284,13 @@ function roi_enqueue_generic_tables() {
|
||||
}
|
||||
|
||||
// Generic Tables CSS
|
||||
// DIFERIDO: Fase 4.2 PageSpeed - below the fold
|
||||
wp_enqueue_style(
|
||||
'roi-generic-tables',
|
||||
get_template_directory_uri() . '/Assets/css/css-global-generic-tables.css',
|
||||
array('roi-bootstrap'),
|
||||
ROI_VERSION,
|
||||
'all'
|
||||
'print' // Diferido para no bloquear renderizado
|
||||
);
|
||||
}
|
||||
|
||||
@@ -256,12 +309,13 @@ function roi_enqueue_video_styles() {
|
||||
}
|
||||
|
||||
// Video CSS
|
||||
// DIFERIDO: Fase 4.2 PageSpeed - below the fold
|
||||
wp_enqueue_style(
|
||||
'roi-video',
|
||||
get_template_directory_uri() . '/Assets/css/css-global-video.css',
|
||||
array('roi-bootstrap'),
|
||||
ROI_VERSION,
|
||||
'all'
|
||||
'print' // Diferido para no bloquear renderizado
|
||||
);
|
||||
}
|
||||
|
||||
@@ -307,10 +361,11 @@ add_action('wp_enqueue_scripts', 'roi_enqueue_main_javascript', 11);
|
||||
*/
|
||||
function roi_enqueue_accessibility() {
|
||||
// Accessibility CSS
|
||||
// CORREGIDO: Fase 4.2 PageSpeed - dependencia 'roi-theme-style' no existía
|
||||
wp_enqueue_style(
|
||||
'roi-accessibility',
|
||||
get_template_directory_uri() . '/Assets/css/css-global-accessibility.css',
|
||||
array('roi-theme-style'),
|
||||
array('roi-main-style'), // Corregido: 'roi-theme-style' -> 'roi-main-style'
|
||||
ROI_VERSION,
|
||||
'all'
|
||||
);
|
||||
@@ -384,12 +439,13 @@ function roi_enqueue_theme_styles() {
|
||||
// );
|
||||
|
||||
// Theme Animations
|
||||
// DIFERIDO: Fase 4.2 PageSpeed - mejoras visuales no críticas
|
||||
wp_enqueue_style(
|
||||
'roi-animations',
|
||||
get_template_directory_uri() . '/Assets/css/css-global-animations.css',
|
||||
array('roi-bootstrap'), // Cambiado de 'roi-theme' a 'roi-bootstrap'
|
||||
array('roi-bootstrap'),
|
||||
'1.0.0',
|
||||
'all'
|
||||
'print' // Diferido para no bloquear renderizado
|
||||
);
|
||||
|
||||
// Theme Responsive Styles
|
||||
@@ -436,12 +492,13 @@ add_action('wp_enqueue_scripts', 'roi_enqueue_theme_styles', 13);
|
||||
*/
|
||||
function roi_enqueue_apu_tables_styles() {
|
||||
// APU Tables CSS
|
||||
// DIFERIDO: Fase 4.2 PageSpeed - below the fold
|
||||
wp_enqueue_style(
|
||||
'roi-tables-apu',
|
||||
get_template_directory_uri() . '/Assets/css/css-tablas-apu.css',
|
||||
array('roi-bootstrap'),
|
||||
ROI_VERSION,
|
||||
'all'
|
||||
'print' // Diferido para no bloquear renderizado
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user