最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How Do I Enqueue a Script into 2 different Footers on the Same Site?

programmeradmin1浏览0评论

I have two different footers being used on a WordPress site. One is the standard footer.phpthe other is for the contact and legal pages and is footer-contact.php

Calling them on the relevant page is straightforward enough - I just a use <?php get_footer('contact'); ?> on the pages where the contact footer is needed.

This 2nd footer design though isn't calling in the scripts. In my functions.php file I use the following, with the last parameter being 'true' which places the JS in the footer.

wp_enqueue_script('main_js', get_theme_file_uri('/js/main.js'), NULL, '1.0', true);

How do I also enqueue my scripts into the second footer i.e. footer-contact.php

I have two different footers being used on a WordPress site. One is the standard footer.phpthe other is for the contact and legal pages and is footer-contact.php

Calling them on the relevant page is straightforward enough - I just a use <?php get_footer('contact'); ?> on the pages where the contact footer is needed.

This 2nd footer design though isn't calling in the scripts. In my functions.php file I use the following, with the last parameter being 'true' which places the JS in the footer.

wp_enqueue_script('main_js', get_theme_file_uri('/js/main.js'), NULL, '1.0', true);

How do I also enqueue my scripts into the second footer i.e. footer-contact.php

Share Improve this question asked Oct 12, 2019 at 22:09 pjk_okpjk_ok 9082 gold badges15 silver badges36 bronze badges 1
  • 1 Do you call the wp_footer() function in your contact footer? – Luckyfella Commented Oct 12, 2019 at 22:29
Add a comment  | 

1 Answer 1

Reset to default 1

While get_footer('name_template_file'); includes the defined footer template it does not output Wordpress wp_enqueued styles and scripts that are defined to be output in the footer automatically. To let your page output all javascript files and stylesheets that supposed to go to the footer call <?php wp_footer(); ?> at the place you want them to be rendered. You could consider to place them in you main template (directly before </body> so there is no need to put them in every single footer template you might include. In most cases it should work fine.

发布评论

评论列表(0)

  1. 暂无评论