fix(php): use wp_add_inline_script for defer compatibility
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user