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.

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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