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

I am displaying post tags like this:

<div class="tags"><?php the_tags('<span>Tags</span>' , ' '); ?> </div>

It works fine, but if the post does not have any tag, then it adds empty div

<div class="tags"></div>

So, how can I use the condition to check if post has any tag, then display above.

share|improve this question
up vote 4 down vote accepted

Make better use of the parameters:

    '<div class="tags"><span>Tags</span>', // before
    ' ', // separator
    '</div>' // after

Now you will never get any useless markup, because WordPress will not print anything when there are no tags for the current post.

share|improve this answer
making use of the integrated parameters is best, therefore +1; to answer your direct question: codex.wordpress.org/Function_Reference/has_tag – Michael Jun 30 '13 at 11:55

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.