I am having some difficulties trying to strip out special characters and spaces from my tags. Using the below code:
<ul class="work_tags_nav">
<li><a class="all" href="#">all.</a></li>
<?php
query_posts(array( 'post_type'=> 'work' ));
if ( have_posts() ) : while ( have_posts() ) : the_post();
$custom_post_tags = get_the_tags();
if ( $custom_post_tags ) {
foreach( $custom_post_tags as $tag ) {
$tags_arr[] = $tag -> name;
}
}
endwhile; endif;
if( $tags_arr ) {
$uniq_tags_arr = array_unique( $tags_arr );
foreach( $uniq_tags_arr as $tag ) {
// LIST ALL THE TAGS FOR DESIRED POST TYPE
$sanitizeTag = sanitize_title($tag);
$tag_link = get_term_by('name', $tag, 'post_tag');
echo '<li><a class="'.$tag.'" href="javascript:void(0)">' .$tag. '.</a></li>';
}
}
?>
</ul>
On this line: echo '<li><a class="'.$tag.'" href="javascript:void(0)">' .$tag. '.</a></li>';
I want the class="" to show the tag but if the tag has "&" or spaces etc. to strip them out. Any ideas?