display tag slug as class per link in tag cloud

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;
}

Leave a Comment