WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is sort of complicated.

I am looking for some php help related to WordPress blog.

The basic requirement is that some HTML code (ad code) is not supposed to run on posts with a specific tag. In simple terms... I do not want to run ads in posts which have a specific tag!

How can it be accomplished?

I believe this would use this WordPress function:


I am not very proficient at PHP. I suppose this can be easily used to run specific code if the post has a specific tag. I want to do the opposite!

share|improve this question
Do you have any code that you can show - might be easier to amend what you already have. – anu Jan 18 '11 at 10:15
Actually I have been using PHP codes that detect the URL for similar requirements. But WordPress tags are not detectable using the URL of the post. Hence the problem. I have added some more info in the post. Please check! – OperaManiac Jan 18 '11 at 10:20
up vote 1 down vote accepted

This is more of basic PHP. You are correct in choice of function, you merely need to reverse the condition with logical Not operator:

if( !has_tag('test') ) {

share|improve this answer
oh lol - has_tag - forgot about that! – anu Jan 18 '11 at 10:30
@anu it helped that it was right there in the question ;) – Rarst Jan 18 '11 at 10:32
i actually added that a bit later. so anu might have missed it! this code seems to be working. i need to test it a bit more because of the extensive caching being done on the site! thanks guys! – OperaManiac Jan 18 '11 at 10:34
yup - it wasn't there in the original question - i added a longwinded piece of code using get_the_tags() and iterating through with foreach - deleted ;) – anu Jan 18 '11 at 10:40
get_the_tags() did not work for me. must have done something wrong. even if it did, it would have been pretty bad on the server because the blog in question has way too many tags and fetching each of them would have resulted in a server meltdown! – OperaManiac Jan 18 '11 at 10:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.