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

jquery - How to load Javascript code or functions.php later in a child theme?

programmeradmin1浏览0评论

I'm placing some JS code in functions.php in my child theme but it loads first than anything else. Thus, I'm trying to get it to load later than the rest cos it needs Jquery. I tried enqueuing WP's built-in jquery like below but I still get "$ not defined" error cos I think the enqueue function runs later.

How can I pull this off? Should I place the code in footer.php?

I'm placing some JS code in functions.php in my child theme but it loads first than anything else. Thus, I'm trying to get it to load later than the rest cos it needs Jquery. I tried enqueuing WP's built-in jquery like below but I still get "$ not defined" error cos I think the enqueue function runs later.

How can I pull this off? Should I place the code in footer.php?

Share Improve this question asked Feb 9, 2022 at 2:23 ratib90486ratib90486 295 bronze badges 3
  • In WordPress jQuery is run in no conflict mode, so you can’t use $. You need to use jQuery. – Jacob Peattie Commented Feb 9, 2022 at 3:20
  • You can use jQuery instead of "$"; or you can follow the method below. digwp.com/2011/09/using-instead-of-jquery-in-wordpress – Jhonatan Villena Commented Feb 9, 2022 at 4:48
  • Can you show the relevant code from your functions file please? – Andy Macaulay-Brook Commented Feb 9, 2022 at 12:15
Add a comment  | 

1 Answer 1

Reset to default 0

Could you set priority parameter like this?

function child_theme_scripts() {
   // wp_enqueue_script
}
add_action( 'wp_enqueue_scripts', 'child_theme_scripts', 11 );
发布评论

评论列表(0)

  1. 暂无评论