Transfer the call scripts from header to the footer on WordPress

/ Published in: PHP
Save to your folder(s)

If you have been able to check your site by means of the PageSpeed ??Insights service, you may notice that it is not an easy task to recruit even 80% of the test results. Only by completing most of the recommendations of Google, you can hope for an increase in performance.

And if the compression of CSS styles and JS scripts is quite capable of any webmaster, then here’s the point “Remove the JavaScript and CSS code that blocks the display of the top of the page” - there are problems. First of all, due to the fact that in WordPress, many scripts are called from “wp_head”, starting from the jquery library and ending with the components of installed plugins.

Copy this code and paste it in your HTML
  1. function footer_enqueue_scripts() {
  2. # Udaliaem JavaScript iz zagolovka
  3. remove_action('wp_head', 'wp_print_scripts');
  4. remove_action('wp_head', 'wp_print_head_scripts', 9);
  5. remove_action('wp_head', 'wp_enqueue_scripts', 1);
  6. # Vyvodim v footer
  7. add_action('wp_footer', 'wp_print_scripts', 5);
  8. add_action('wp_footer', 'wp_enqueue_scripts', 5);
  9. add_action('wp_footer', 'wp_print_head_scripts', 5);
  10. }
  11. add_action('after_setup_theme', 'footer_enqueue_scripts');


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.