How do I hide the tag-container when there’s no tags?

I was wondering how I could get #tag-container to only display when there’s tags. How do I do this? I’m thinking there’s some if and else statements, but I can’t figure out how to correctly write it…

<div class="tag-container">
    <p><?php the_tags(); ?></p>
</div>

Related posts

Leave a Reply

3 comments

  1. In addition to the other answers I would store the rendered tags in a variable to not call the same function twice.

    <?php $tags = get_the_tag_list( __('Tags: '), ', ' ); ?>
    <?php if( !empty( $tags ) ) : ?>
    <div class="tag-container">
        <p><?php echo $tags; ?></p>
    </div>
    <?php endif; ?>