gpt4 book ai didi

javascript - 添加到 functions.php 时,Google Analytics 事件跟踪代码会破坏 wordpress 站点

转载 作者:行者123 更新时间:2023-11-30 14:55:41 25 4
gpt4 key购买 nike

我使用以下代码通过 functions.php 添加了一个显示在我的产品页面上的全局按钮:

function add_content_after_addtocart_button_func() {
echo '
<div class="wsbl_line"><a href="http://line.me/R/msg/text/website.com"
title="share using Line" rel="nofollow"
class="wp_social_bookmarking_light_a"><img src="sample-image.png"
width="135" height="30" class="wp_social_bookmarking_light_img"></a></div>';
}

将以下 Google Analytics 事件跟踪代码添加到上述代码后,网站就会中断。

function add_content_after_addtocart_button_func() {
echo '
<div class="wsbl_line"><a href="http://line.me/R/msg/text/website.com"
title="share using Line" rel="nofollow"
class="wp_social_bookmarking_light_a" onClick="ga('send', 'event', 'social', 'line-button-click', 'line-button');"><img src="sample-image.png"
width="135" height="30" class="wp_social_bookmarking_light_img"></a></div>';
}

我已经通过将跟踪代码直接放在页面中成功地测试了它

<a href="website.com" onClick="ga('send', 'event', 'social', 'line-button-
click', 'line-button');">anchor text</a>

我做错了什么?

最佳答案

如果你用单引号打开代码并在你想要回显的代码中使用它们,你需要转义它,像这样:

function add_content_after_addtocart_button_func() {
echo '
<div class="wsbl_line"><a href="http://line.me/R/msg/text/website.com"
title="share using Line" rel="nofollow"
class="wp_social_bookmarking_light_a" onClick="ga(\'send\', \'event\',
\'social\', \'line-button-click\', \'line-button\');"><img src="sample-
image.png"
width="135" height="30" class="wp_social_bookmarking_light_img"></a></div>';
}

即使你用 "双引号打开回显,它也会中断,因为你正在回显的代码中有双引号。我建议你使用一些带有 php 语法高亮的文本编辑器来查看它在哪里中断。

试试我给你的代码,问候

关于javascript - 添加到 functions.php 时,Google Analytics 事件跟踪代码会破坏 wordpress 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47303176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com