请注意,我是php和wordpress的新手。
我需要在我的wordpress网站上呈现2个不同的谷歌adwords脚本。经过大量研究后,我得出结论,最有效的解决方案是一个条件内部page.php,它解析page_id并在条件满足时注入相应的代码。
我需要在A,B和C页中注入一个脚本。我已经能够很好地完成这项工作了。
但是,我还需要在Page X中注入另一个脚本。它使用相同的代码 - 但无论出于何种原因它都无法正常工作。
我意识到可能还有其他问题使得这个脚本注入不可能,但我想向社区询问我的php语法或逻辑是否存在根本错误。
以下是我使用的代码:
// THIS WORKS
<?php if ( is_page( array( 600,601,602 ))) { ?>
<!-- Google Code for Pages A, B, and C -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 999999999;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "afafafafafafafaf";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/99999999/?label=asdafasfafafafaf&guid=ON&script=0"/>
</div>
</noscript>
<?php } ?>
// THIS DOESN'T WORK
<?php if ( is_page( array( 700 ))) { ?>
<!-- Google Code for Page X -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 9999999999;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "ljljkjjljjljljljjkl";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/99999999999/?label=ljljkjjljjljljljjkl&guid=ON&script=0"/>
</div>
</noscript>
<?php } ?>
我还尝试将它们加入到if / elsif / else语句中,但这会破坏它们。
我重新安排了3页数组在底部的顺序,3页继续工作,但1页仍然不起作用。
任何可以帮助我解决此问题的反馈都是受欢迎的。感谢。
答案 0 :(得分:0)
不使用数组时不要使用数组。
也试试这个:
<?php if ( is_page( array( 600,601,602 ))) { ?>
<!-- Google Code for Pages A, B, and C -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 999999999;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "afafafafafafafaf";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/99999999/?label=asdafasfafafafaf&guid=ON&script=0"/>
</div>
</noscript>
<?php } elseif ( is_page(700)) { ?>
<!-- Google Code for Page X -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 9999999999;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "ljljkjjljjljljljjkl";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/99999999999/?label=ljljkjjljjljljljjkl&guid=ON&script=0"/>
</div>
</noscript>
<?php } ?>