dpbf62565 2017-03-28 13: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 16: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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器