WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Your Answer


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.