How to not show tags if the post doesn’t have any?

I currently have the following trying to avoid showing tags (the icon in this case) when there aren’t any, but the icon continues to show up. Any thoughts?

<?php if ( is_singular() && function_exists('the_tags') ) : ?> 
    <p><i class="icon-tags"></i><?php the_tags('', ', ', ' '); ?></p>
<?php endif; ?>

2 Answers
2

Get a string value for the tags and print it only if there are tags:

$tags = get_the_tag_list('', ', ', ' ');

if ( "" !== trim( $tags ) )
{
    echo "<p><i class="icon-tags"></i>$tags</p>";
}

Leave a Comment