In Wordpress how to move jQuery to the footer?

The script connects dynamically using the functions wp_head(). Found a few recipes on this topic, but none of them works, if you use plugins that have dependencies spelled out jQuery. When this is the javascript code of these plugins are easy to carry in the footer through the wordpress API. That is, the transfer jQuery in the footer these plugins will not break, but this library to transfer is not obtained. I would not want to rule handles the code of the plugins, disabling the jquery, then to connect it in the footer manually. This will break the ability to update. While comes to mind only to wrap the wp_head() to ob_start() and output buffer content in the footer. Experts of WordPress, tell me how to do it properly?
June 8th 19 at 16:32
1 answer
June 8th 19 at 16:34
What you want to Google? Your link function wp_register_script, which in turn uses the function $wp_scripts->add_data(). This function will connect jquery in the footer if the site uses scripts that have dependencies spelled out jquery.

Use the code the link leads to the fact that instead of default jquery in the head connects the transmitted version of jquery.

The nuances of your method is chewed https://wordpress.stackexchange.com/a/240612

Maybe you have some additional instructions to the above link? - Darrion.Gaylo commented on June 8th 19 at 16:37
I took the first link from a search, apparently you need specific. But who knows your specific situation. Your option is simply unregister the JQuery and then register again the default JQuery by adding at the end true:
wp_register_script( $handle, $src, $deps, $ver, $in_footer );

wp_register_script('jquery', includes_url('/js/jquery/jquery.js'), false, null, true);

Specific instructions: https://misha.blog/wordpress/pagespeed-css-javascr... especially for you.
This function will connect jquery in the footer if the site uses scripts that have dependencies spelled out jquery.
this is exactly the opposite of a true statement. If you have dependencies, the script spelled out 'jquery' and if it is not declared, the script will not connect. Test is easy, you can put the default in WP and give him the Contact Form 7, it just spelled out this dependence. If I'm right, then the form will work with Ajax.
Update: klocko.zorcastudio.org/sample-page
5a76f95041ada096528833.jpeg - Baylee_Kulas commented on June 8th 19 at 16:40
how to determine why your code is not working on a specific website properly? Where to catch the change in the position of jquery?

The situation is such that disabling the jquery is working correctly. A subsequent connection jquery returns it into place. At the moment the only working option, which brings with jquery dependent scripts in the footer, selected at random and looks like this:

add_action('wp_enqueue_scripts', 'jquery_to_footer_part1'); 

jquery_to_footer_part1 function() { 
 wp_deregister_script('jquery'); 
}

add_action( 'wp_footer', 'jquery_to_footer_part2' );

jquery_to_footer_part2 function() {
 wp_register_script('jquery', includes_url('/js/jquery/jquery.js'), false, null, true); 
wp_enqueue_script('jquery');
}


I believe that between events there is an additional registration jquery, which interrupts the previous one. I'd love to understand the unusual behavior of the engine. In General the result is a rather clever trick that I would not like to leave in the code - Darrion.Gaylo commented on June 8th 19 at 16:43
You do not see the difference between Your code and the code in the link: https://misha.blog/wordpress/pagespeed-css-javascr... ???
add_action('wp_enqueue_scripts', 'true_peremeshhaem_jquery_v_futer'); 

true_peremeshhaem_jquery_v_futer function() {
 // remove standard registration jQuery
wp_deregister_script('jquery');
 // register for connection in the footer, a description of the parameters in the function documentation (link just above)
 wp_register_script('jquery', includes_url('/js/jquery/jquery.js'), false, null, true);
 // plug-in
wp_enqueue_script('jquery');
}

Nothing unusual in the behavior of the engine no, just need to use it correctly.
PYSY. If your "broken" version is different, please provide it. Crutches are not very interesting. We try to solve the problem, not create new ones. - Baylee_Kulas commented on June 8th 19 at 16:46

Find more questions by tags WordPress