Support » Themes and Templates » Show tag icons instead of tag text.

Show tag icons instead of tag text.

  • I would like show tag icons instead of tag icons.
    As an example, Instead of the tag text “Photoshop” I would like to show Photoshop icon.
    Any help would be cordially appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael


    Forum Moderator

    you could use some code, starting with ‘get_the_tags()’:


    for instance:

    $separator ='';
    $posttags = get_the_tags();
    if ($posttags) {
      $img_path = get_bloginfo('stylesheet_directory');
      foreach($posttags as $tag) {
        $image = 'tag_icon_' . $tag->slug . '.jpg';
        $link = get_tag_link( $tag->term_id);
        $output .= $separator . '<a href="' . $link . '">';
        $separator =' '; // this adds a space between the icons; you can change it
          if(file_exists(STYLESHEETPATH.'/images/'.$image)) {
          $output .= '<img src="' . $img_path.'/images/'.$image . '" alt="tag ' . $tag->name .' icon" />';
          } else {
          $output .= $tag->name;
        $output .= '</a>';
      echo $output;


    the icon image needs to be in the /images folder of the theme;
    named tag_icon_tag-slug.jpg

    for instance, your tag name is ‘Beautiful Day Today’ then the image name has to be tag_icon_beautiful-day-today.jpg

    the code checks for the image, and outputs the tag name if the image is not found.

    thanks for the reply, this code is working for me.
    Yet there is something wrong with it, when I insert it into the loop.

    I am displaying the icons on the post excerpts within categories and archives, but this not work correct.

    The first post will be displayed correct, the second one for example contains its tags, but it also contains the tags of the first post and so on.

    All the tags get added to following posts. It does not display the icons only for the appropriate post.

    Somehow the php query is not getting closed. Unfortunately I am no php expert, therefore I am not able to point my finger on it.

    Thanks for clearing this up.



    Forum Moderator

    it is caused by the way the output string is added together from bits.

    at the beginning of the code, after this line:
    $separator ='';
    set the $output to empty;

    $output = ''; //initialize clean output;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show tag icons instead of tag text.’ is closed to new replies.