Answer the question
In order to leave comments, you need to log in
How to move styles to the footer in the new WordPress 5.8?
Previously working code stopped working in the new version of WP.
function footer_enqueue_scripts(){
remove_action('wp_head','wp_print_scripts');
remove_action('wp_head','wp_print_head_scripts',9);
remove_action('wp_head','wp_enqueue_scripts',1);
add_action('wp_footer','wp_print_scripts',5);
add_action('wp_footer','wp_enqueue_scripts',5);
add_action('wp_footer','wp_print_head_scripts',5);
}
add_action('after_setup_theme','footer_enqueue_scripts');
: Trying to get property 'queue' of non-object in
site\wp-includes\script-loader.php
on line
2652
Warning
: Invalid argument supplied for foreach() in
site\wp-includes\script-loader.php
on line
2652
Answer the question
In order to leave comments, you need to log in
// Move jQuery to the footer
function theme_move_jquery_to_footer() {
wp_scripts()->add_data( 'jquery', 'group', 1 );
wp_scripts()->add_data( 'jquery-core', 'group', 1 );
wp_scripts()->add_data( 'jquery-migrate', 'group', 1 );
}
add_action( 'wp_enqueue_scripts', 'theme_move_jquery_to_footer' );
// Enqueue scripts and styles.
function theme_scripts() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.min.js' ), false, NULL, true );
wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
You shouldn't do that, it's an anti-pattern and a wild crutch.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question