Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress函数主题选项格式_Php_Wordpress_Function_Google Analytics - Fatal编程技术网

Php Wordpress函数主题选项格式

Php Wordpress函数主题选项格式,php,wordpress,function,google-analytics,Php,Wordpress,Function,Google Analytics,我已经创建了一个wordpress主题,并为最终用户创建了一系列选项来更改站点的某些区域 我用一个文本区来处理谷歌分析代码的用户问题 文本区域可以工作,但分析代码的输出意味着它不工作 在my functions.php文件中,我有一个文本区域供用户输入其分析代码: array ( 'key' => 'field_52e7a858b4951', 'label' => __("Tracking code",

我已经创建了一个wordpress主题,并为最终用户创建了一系列选项来更改站点的某些区域

我用一个文本区来处理谷歌分析代码的用户问题

文本区域可以工作,但分析代码的输出意味着它不工作

在my functions.php文件中,我有一个文本区域供用户输入其分析代码:

array (
                    'key' => 'field_52e7a858b4951',
                    'label' => __("Tracking code", 'dansiop'),
                    'name' => 'google_analytics',
                    'type' => 'textarea',
                    'instructions' => __("Copy and paste your Google Analytics tracking code here. You can create a free account at: http://www.google.com/analytics/", 'storini'),
                    'default_value' => '',
                    'placeholder' => '',
                    'maxlength' => '',
                    'formatting' => 'none',
                ),
否在我的管理中,我有所需的文本区域:

[无法发布图像,因为这里是新的]

因此,当用户输入其特定的分析代码时,例如:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'XX-XXXXXXXX-X', 'auto');
  ga('send', 'pageview');

</script>
出于明显的原因,我在分析代码中屏蔽了特定ID

有人知道为什么会这样吗

非常感谢您的帮助,我们在网上找不到任何与此相关的信息

编辑: 我在上面/正文的页脚处重复代码:

<?php if( get_field('google_analytics', 'option') ) : ?><?php the_field('google_analytics', 'option'); ?><?php endif ?>

为什么不尝试使用
html\u entity\u decode()

您应该使用
html\u entity\u decode('Your-analysis-code-variable')转到页脚并回显/打印代码



如果打印或var\u转储该字段,该值是否已转义,还是仍保留其未格式化的值

您好,在广告之前从未使用过该代码,我尝试过:毫无乐趣。@DanDavies我已经更新了我的答案,您可以尝试使用该代码,以节省您的时间和精力,但这不起作用-该代码现在已经改进,并且看起来正确,但代码中的任何字符都没有显示出来-例如ga('send','pageview');显示为ga(';发送';,';页面视图';)-还有其他想法吗?啊,我错过了。我已经更新了我的答案,这将解决您的问题您的传奇-感谢这一点。我已经接受了你的回答,但还不能投票,因为我没有足够的声誉。再次感谢你。
<?php if( get_field('google_analytics', 'option') ) : ?><?php the_field('google_analytics', 'option'); ?><?php endif ?>
<?php 
if( get_field('google_analytics', 'option') ) :
    echo html_entity_decode(get_field('google_analytics', 'option'), ENT_QUOTES, "ISO-8859-1");
endif 
?>