Skip to content

Instantly share code, notes, and snippets.

@mdjwel
Created January 30, 2017 21:42
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 mdjwel/f4911256dee73dab01b41faa824d45b4 to your computer and use it in GitHub Desktop.
Save mdjwel/f4911256dee73dab01b41faa824d45b4 to your computer and use it in GitHub Desktop.
<?php
function prefix_tags($before = null, $sep = ', ', $after = '', $attr=[]) {
$html = '';
$tags = get_the_tags();
$tagItems = count($tags);
$i = 0;
if(is_array($attr)){
foreach ($attr as $name => $value) {
$attr = " $name=" . '"' . $value . '"';
}
}
if(is_array($tags)) {
foreach($tags as $tag) {
$html .= $before;
$html .= '<a href="'.esc_url(home_url('/'))."tag/".$tag->slug.'"' . $attr . '>' .$tag->name. '</a>' . $after;
if(++$i != $tagItems) {
$html .= $sep;
}
}
}
echo $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment