Skip to content

Instantly share code, notes, and snippets.

@braginteractive
Created July 9, 2015 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braginteractive/b022f986a8c1a739f7b6 to your computer and use it in GitHub Desktop.
Save braginteractive/b022f986a8c1a739f7b6 to your computer and use it in GitHub Desktop.
Add a class to each tag in WordPress
<?php
$tags = get_the_tags();
$html = '<div class="post_tags">';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment