Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 3 down vote accepted

Make better use of the parameters:

<?php 
the_tags(
    '<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
2  
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

 
discard

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.