WordPress: Display Tags as Comma Separated List


Here is a quick function to display a comma separated list of the tags in your posts.

function comma_tags($tags, $show_links = true)
{
  if($tags)
  {
    $t = array();
    foreach($tags as $tag)
    {
      $t[] = (!$show_links) ? $tag->name : '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>';
    }
    return implode(", ", $t);
  }
  else
  {
    return false;
  }
}

And here is how you would call it inside of the WordPress loop. The second parameter show the tags without links.

// WITH LINKS
$tags = comma_tags( get_the_tags() );

// WITHOUT LINKS
$tags = comma_tags( get_the_tags(), false );