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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么