Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to filter wp_generate_tag_cloud so each of the tag links include the slug as a class. More specifically, I would like to output "tag-" + the tag slug.

Currently what is assigned as the class is "tag-link-" + the tag ID.

The the end, I would happy with either a replacement or just adding this additional class to the links.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

one possible way: add a filter in functions.php of your theme:

add_filter ( 'wp_tag_cloud', 'tag_cloud_slug_class' );

function tag_cloud_slug_class( $taglinks ) {
    $tags = explode('</a>', $taglinks);
    $regex = "#(.*tag-link[-])(.*)(' title.*)#e";
        foreach( $tags as $tag ) {
        $tagn[] = preg_replace($regex, "('$1$2 tag-'.get_tag($2)->slug.'$3')", $tag );
        }
    $taglinks = implode('</a>', $tagn);
    return $taglinks;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.