<?php
/**
* Strips html from tags
*
* @param array $array_of_tags
* @param bool (true or false) true = prints out the tags / false = saves them into one variable for later usage
* @return string
*/
if(!function_exists('strip_html_from_tags'))
{
function strip_html_from_tags($tags, $echo = true)
{
$originalArray = $tags; // keep original array intact for now
$lastTag = array_pop($tags); // we only need the name from this
$separator = ", "; // Replace comma with another character as your new separator
$output = "";
foreach($originalArray as $tag) // loop throught the $originalArray to capture each tag name and save them in the $output variable
{
$output .= $tag->name;
// determine the use of the separator
$output .= ($tag->name == $lastTag->name) ? '' : $separator; // if we're on the $lastTag, delete de $separator
}
unset($lastTag); // no need this anymore
// Display type
if($echo)
{
echo $output; // prints them on screen
}
else
{
return $output; // saves them for later parsing (maybe to link them back?)
}
}
}
/*--------------------------------------------
| Usage example - you have to be in the loop |
---------------------------------------------*/
// Ex 1: print your tags
$tags = get_the_tags();
strip_html_from_tags($tags); // this will echo out the tags
echo "";
// Ex 2 (using the 2nd parameter)
$tags = get_the_tags();
$tags = strip_html_from_tags($tags, false); // you may save them for later usage
// An example of the above usage (passing the 2nd parameter) would be:
$myStrippedTags = explode(', ', $tags);
// now $myStrippedTag is an array of tags - do something to each of them
foreach($myStrippedTags as $tag)
{
// Maybe you would like to link them back?
// ...but I found this unnecesary to link them back - because you will reinvent the "the_tags" function
echo "<a href='".get_bloginfo('url')."/tag/{$tag}' title='{$tag}'>{$tag}</a>";
}
?>
Well – I did the best I can to help you, as my english isn’t the best.
Hope you will find this useful.
Bye now.
Tici