dpbf62565 2017-03-28 05:19
浏览 48
已采纳

WordPress在页脚中声明了JQuery

I've been handed a WordPress (WP) site from a 3rd party. I work with Drupal, so I'm not well-rounded in WP.

That said, I'm attempting to install Google Tag Manager (GTM). However, I'm getting console errors, stating that JQuery is not defined. I've discovered that JQuery is defined in the <footer>, not the <head>. I've had this issue in the past with Drupal, but I'm not sure where to begin with WP.

After looking at the template, I've discovered that there is a <?php wp_head(); ?> tag in the head and there is a <?php wp_footer(); ?> tag in the footer. Both tags inject scripts, but obviously, JQuery is injected through the footer tag. From what I can tell, the scripts are compiled in the script-loader.php document, but the document is a little overwhelming. I'm not exactly sure what to move around in order to get JQuery injected through the <?php wp_head(); ?> tag.

I've uploaded the script-loader.php document to Google Drive. I'll put it into a .txt file so that it's readable within GDrive.

Please let me know if there's anything else I can provide. Any helpful feedback is appreciated!

  • 写回答

2条回答 默认 最新

  • douchuntang2827 2017-03-30 08:39
    关注

    After posting on the Stack Exchange site for WordPress, I found a solution. Basically, I had to enqueue the GTM script, declaring JQuery as a dependency to it. The script I was provided is as follows:

    function my_theme_add_gtm_script() {
        wp_enqueue_script('google-track-manager', get_template_directory_uri() . '/assets/js/gtm.js', array('jquery'), false, false);
    }
    add_action('wp_enqueue_scripts', 'my_theme_add_gtm_script');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部