viktorix
Member
Posted 1 year ago #
I'm trying to figure out a way to display two different ad codes based on the article tag. Here's what I was trying to do but it's not working, would really appreciate some feedback. This is part of sidebar.
<?php if (is_tag('example')) {
JS AD CODE HERE
}
else { ?>
ALT JS AD CODE HERE
<?php } ?>
Thanks in advance!
is_tag('example') translates to "if this is the page listing all posts with the example tag"? Is that what you were after?
viktorix
Member
Posted 1 year ago #
Hey esmi,
Yes, if a post contains "example" tag it will show ad code #1, but if it doesn't contain it then show ad code #2.
I have to do this due to some js conflicts on a service that we use while they are looking into the problem.
Thanks for your reply,
Viktor
if a post contains "example" tag it will show ad code #1
that would be has_tag()
http://codex.wordpress.org/Function_Reference/has_tag
viktorix
Member
Posted 1 year ago #
Thanks for the info. So if I change is_tag to has_tag, will it work? I just want to make sure if else is setup right.
just make sure to switch cleanly from php to js etc;
example:
<?php if (has_tag('example')) { ?>
JS AD CODE HERE
<?php }
else { ?>
ALT JS AD CODE HERE
<?php } ?>
viktorix
Member
Posted 1 year ago #
Excellent. Thanks a lot for your help. Really appreciate it.