Wordpress功能主题选项格式化


Wordpress Functions Theme options formatting

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

我正在处理一个文本区域的问题,该区域用于处理用户的谷歌分析代码。

文本区域有效,但分析代码的输出意味着它不起作用。

在我的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',
                ),

不,在我的管理员中,我有所需的文本区域:

[由于是新用户,无法在此处发布图像]http://www.dansiop.com/analytics.png

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

<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>

代码显示在网站的页脚中。它被放置在正确的位置,但当我查看源代码时,我看到的分析代码如下:

&lt;script&gt;
  (function(i,s,o,g,r,a,m){i[&#039;GoogleAnalyticsObject&#039;]=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,&#039;script&#039;,&#039;//www.google-analytics.com/analytics.js&#039;,&#039;ga&#039;);
  ga(&#039;create&#039;, &#039;XX-XXXXXXXX-X&#039;, &#039;auto&#039;);
  ga(&#039;send&#039;, &#039;pageview&#039;);
&lt;/script&gt;

出于显而易见的原因,我在分析代码中屏蔽了特定的ID。

有人知道为什么会发生这种事吗?

非常感谢您的帮助,但在网上找不到任何关于此事的信息。

编辑:我在上面/正文的页脚中用以下代码回显:

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

为什么不尝试使用html_entity_decode()

您应该转到页脚并使用html_entity_decode('Your-analytic-code-variable'); 回显/打印代码

<?php 
if( get_field('google_analytics', 'option') ) :
    echo html_entity_decode(get_field('google_analytics', 'option'), ENT_QUOTES, "ISO-8859-1");
endif 
?>

如果打印或var_dump字段,该值是否已经转义,还是仍然保持其未格式化的值?