WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm nearly there with this, but I need to highlight the current tag link/archive being viewed:

<ul id="blog-tags">
            $tags = get_tags();
            if ($tags) {
                foreach ($tags as $tag) {
                    echo '<li><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></li>';

I'd like to apply <li class="active-tag"> to the list item that contains the active tag in the code above - can anyone help me with that please?

Many thanks


share|improve this question
Look at this thread : questions/16816 – JMau Aug 11 '13 at 13:05
up vote 2 down vote accepted

Compare $tag->term_id with the value from get_queried_object_id(). You have to cast the former to integer, because it is provided as a string for no good reason.

<ul id="blog-tags">
$tags = get_tags();
if ( $tags ) {
    foreach ( $tags as $tag ) {
        echo '<li>';

        if ( (int) $tag->term_id === get_queried_object_id() )
            echo "<b>$tag->name</b>";
                '<a href="%1$s">%2$s</a>',
                get_tag_link( $tag->term_id ),

        echo '</li>';
share|improve this answer
Great, fantastic answer, thanks toscho! – Osu Aug 11 '13 at 13:08
Nice, fav it now – JMau Aug 11 '13 at 13:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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