0

I am having issues displaying tags only if there is tags and including php inside of it as well. This is what I tried but nothing is showing.

<?php
if( has_tag() ) { ?>

    <!-- Start of tags -->

        <?php echo get_the_term_list( $post->ID, 'download_tag', 'Tags ', ', ', '' ); ?>

    <!-- End of tags  -->

<?php
}
?>
1

The has_tag function doesn't do what you expect here. It actually means 'post has tag' checks if a post (or current post) has a particular tag. Something like has_tag( 'self-important-tag' ). See the codex

If you leave out the conditional and the post has no tags, get_the_termlist will echo nothing because it checks if the post has terms internally:

<!-- Start of tags -->
    <?php echo get_the_term_list( $post->ID, 'download_tag', 'Tags ', ', ', '' ); ?>
<!-- End of tags  -->
0

Inside your condition, try this:

<?php 
    $var = get_the_term_list( $post->ID, 'download_tag', 'Tags ', ', ', '' );
    echo $var;
?>

[I have not tested this!]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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