在WordPress上把调用脚本从页眉转移到页脚

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在WordPress上把调用脚本从页眉转移到页脚相关的知识,希望对你有一定的参考价值。

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.
RU ? EN
  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');

以上是关于在WordPress上把调用脚本从页眉转移到页脚的主要内容,如果未能解决你的问题,请参考以下文章

带有侧导航和内容区域的 CSS3/HTML5 粘性页眉/页脚

使用 ACF 输出单个页眉样式和页脚脚本

如何为wordpress主题添加自定义页眉和页脚

使用不同的页眉和页脚在Drupal上创建页面

如何将 wordpress 博客与网站页眉和页脚设计集成到 php 网站博客页面?

添加谷歌分析到页脚