admin管理员组文章数量:1328893
i have the following snippet on the site which is working perfectly fine but sometimes I have multiple pages where I want to trigger the event snippet from google, my questions can I add multiple ids using comma?
this is the code I am using which is working fine.
<?php if( $post->ID == 13052) { ?>
<!-- Event snippet for thank-you page --><script> gtag('event', 'conversion', {'send_to': 'AW-105871269/5v9gsts6dbdsJ-Kl'});</script>
<?php } ?>
i have the following snippet on the site which is working perfectly fine but sometimes I have multiple pages where I want to trigger the event snippet from google, my questions can I add multiple ids using comma?
this is the code I am using which is working fine.
<?php if( $post->ID == 13052) { ?>
<!-- Event snippet for thank-you page --><script> gtag('event', 'conversion', {'send_to': 'AW-105871269/5v9gsts6dbdsJ-Kl'});</script>
<?php } ?>
Share
Improve this question
edited Jul 14, 2020 at 14:41
mozboz
2,6281 gold badge12 silver badges23 bronze badges
asked Jul 13, 2020 at 20:14
sub0sub0
153 bronze badges
1 Answer
Reset to default 1This is more of a PHP question than specifically Wordpress, but you can use PHP's in_array
to test if $post->ID
is in a bunch of values, like this:
<?php if( in_array($post->ID, [13052, 1234, 4242]) ) { ?>
<!-- Event snippet for thank-you page --><script> gtag('event', 'conversion', {'send_to': 'AW-105871269/5v9gsts6dbdsJ-Kl'});</script>
<?php } ?>
本文标签: phpCheck postgtID against multiple values
版权声明:本文标题:php - Check $post->ID against multiple values 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742263020a2442868.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论