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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745085707a4610392.html

相关推荐

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

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

    17小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信