Wp_enqueue_script in footer

There were problems with the script in the footer.

wp_deregister_script('jquery'); wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', array(), false, true); 

Here's the definition of wp_enqueue_script:

 wp_enqueue_script( $handle ,$src ,$deps ,$ver ,$in_footer ); 

As you can see, I set the value of $ in_footer to true. This does not work for me. Without this argument, it works fine and puts it in header.php. Why doesn't it work with $ in_footer?

+6
source share
3 answers

By default, JavaScripts by default, WordPress does not move to the footer, the workaround is to add its path:

 wp_enqueue_script('jquery','/wp-includes/js/jquery/jquery.js','','',true); 

See detailed post about it.

+11
source

Make sure you have wp_footer() right before the </body> . See $ in_footer for more details. You must also call this before starting wp_head. Try also this action.

 add_action('wp_enqueue_scripts', 'add_scripts_to_pages'); 

Another thing to try is to use NULL as the 3rd and 4th parameters.

+7
source

As a complement to @Nick's answer;

If you have a problem with PHP before wp_footer() , you will not be able to see your script in the footer. Source https://wordpress.org/support/topic/enqueuing-scripts-in-footer-does-not-working-with-wordpress-36 .

0
source

Source: https://habr.com/ru/post/911123/


All Articles