diff --git a/wp-content/themes/apus-theme/inc/enqueue-scripts.php b/wp-content/themes/apus-theme/inc/enqueue-scripts.php index e46bc664..b00c8064 100644 --- a/wp-content/themes/apus-theme/inc/enqueue-scripts.php +++ b/wp-content/themes/apus-theme/inc/enqueue-scripts.php @@ -194,8 +194,8 @@ function apus_enqueue_custom_assets() { 'apus-main-js', get_template_directory_uri() . '/assets/js/main.js', array('apus-bootstrap-js'), - '1.0.2', // Cache bust: remove defer for wp_localize_script compatibility - true // Load in footer (defer removed for wp_localize_script to work) + '1.0.3', // Cache bust: force remove defer with filter + true // Load in footer ); // Localize script to pass theme URL to JavaScript @@ -211,6 +211,21 @@ function apus_enqueue_custom_assets() { add_action('wp_enqueue_scripts', 'apus_enqueue_custom_assets', 11); +/** + * Remove defer from apus-main-js to make wp_localize_script work + * WordPress 6.3+ adds defer automatically to footer scripts with dependencies + * but wp_localize_script requires synchronous execution + */ +function apus_remove_defer_from_main_js($tag, $handle) { + if ('apus-main-js' === $handle) { + // Remove defer and data-wp-strategy attributes + $tag = str_replace(' defer', '', $tag); + $tag = str_replace(' data-wp-strategy="defer"', '', $tag); + } + return $tag; +} +add_filter('script_loader_tag', 'apus_remove_defer_from_main_js', 20, 2); + /** * Enqueue footer styles */