Forums

[resolved] How to echo current tag slug (3 posts)

  1. cognitions
    Member
    Posted 4 years ago #

    On a category.php the following works to echo the current category slug:

    <?php
    if (is_category()) {
    $yourcat = get_category ($cat);
    echo 'the slug is '.$yourcat->slug;
    }
    ?>

    Please could someone tell me how to modify this so that on tag.php I can echo the current tag slug. I have tried everything.

    Thank you.

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    if ( is_tag() ) {
    $term_id = get_query_var('tag_id');
    $taxonomy = 'post_tag';
    $args ='include=' . $term_id;
    $terms = get_terms( $taxonomy, $args );
    echo '<p> slug is ' . $terms[0]->slug . '</p>';
    }
    ?>

    Related:
    Tag_Templates

  3. cognitions
    Member
    Posted 4 years ago #

    Thank you very much indeed! It works perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags