From a2c4f857be3327d86eb4ffdb20d054cfd85dce9f Mon Sep 17 00:00:00 2001 From: FrankZamora Date: Wed, 10 Dec 2025 15:57:31 -0600 Subject: [PATCH] fix(php): use wp_add_inline_script for defer compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wp_localize_script doesn't work correctly with WordPress 6.3+ when using strategy => 'defer'. Switch to wp_add_inline_script with 'before' position to ensure roiAdsenseConfig is defined before the deferred script executes. šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- Inc/enqueue-scripts.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Inc/enqueue-scripts.php b/Inc/enqueue-scripts.php index e2a98804..16b4d28b 100644 --- a/Inc/enqueue-scripts.php +++ b/Inc/enqueue-scripts.php @@ -491,16 +491,23 @@ function roi_enqueue_adsense_loader() { ); // Pasar configuración de lazy loading a JavaScript + // Nota: wp_add_inline_script funciona mejor con strategy => 'defer' que wp_localize_script $lazy_enabled = roi_get_component_setting('adsense-placement', 'behavior', 'lazy_loading_enabled', true); $lazy_rootmargin = roi_get_component_setting('adsense-placement', 'behavior', 'lazy_rootmargin', '200'); $lazy_fill_timeout = roi_get_component_setting('adsense-placement', 'behavior', 'lazy_fill_timeout', '5000'); - wp_localize_script('roi-adsense-loader', 'roiAdsenseConfig', array( + $config = array( 'lazyEnabled' => (bool) $lazy_enabled, 'rootMargin' => (int) $lazy_rootmargin . 'px 0px', 'fillTimeout' => (int) $lazy_fill_timeout, 'debug' => defined('WP_DEBUG') && WP_DEBUG, - )); + ); + + wp_add_inline_script( + 'roi-adsense-loader', + 'window.roiAdsenseConfig = ' . wp_json_encode($config) . ';', + 'before' + ); } add_action('wp_enqueue_scripts', 'roi_enqueue_adsense_loader', 10);