Wordpress: Adding class selectors to the_tags(); output Wordpress: Adding class selectors to the_tags(); output wordpress wordpress

Wordpress: Adding class selectors to the_tags(); output


It worked, thank you! This is what I did:

<?php$post_tags = get_the_tags();if ($post_tags) {  foreach($post_tags as $tag) {    echo '<a href="'; echo bloginfo();    echo '/?tag=' . $tag->slug . '" class="' . $tag->slug . '">' . $tag->name . '</a>';  }}?>


Also you can overload working of get_the_tags(); function. Just add next code to your functions.php theme file:

// add custom class to tagfunction add_class_the_tags($html){    $postid = get_the_ID();    $html = str_replace('<a','<a class="class-name"',$html);    return $html;}add_filter('the_tags','add_class_the_tags');


this code from www.lawturn.com

/* SlSlib tags add class */<?php if(has_tag()) : ?>    <?php    $tags = get_the_tags(get_the_ID());      foreach($tags as $tag){        echo '<a href="'.get_tag_link($tag->term_id).'" rel="tag" class="tag-'.$tag->name.'">'.$tag->name.'</a>';    } ?><?php endif; ?>