How to add a class to Tag Cloud items – WordPress

If you want to extend the WordPress Tag Cloud Widget with your own custom CSS class, you can easily use the wp_generate_tag_cloud_data filter like so:

function extend_tag_cloud($tag_data) { return array_map ( function ( $item ) { $item['class'] .= ' your-custom-class'; return $item; }, (array) $tag_data ); } add_filter( 'wp_generate_tag_cloud_data', 'extend_tag_cloud');
Code language: PHP (php)


About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

Leave a Reply

Add <code> Some Code </code> if you need to.