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
Add a comment  | 

1 Answer 1

Reset to default 1

This 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