0

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.

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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