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 } ?>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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 } ?>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0