How To Remove Tag Clouds Inline Style

In wordpress, using Tag cloud widget we can display tags used on your site. Themes designed for WordPress do not have CSS in their style sheets for formatting the WordPress tag cloud. The CSS for the tag cloud is built into the WordPress wp_tag_cloud() function, which is found in wp-includes/category-template.php.

However, tag cloud widget comes with some inline styling, for example, font-size but in SEO rules, it’s better to move all inline css to external file for better site performance. So here we show you how to remove tag clouds inline style.

So here is my code add this code on your theme’s functions.php file of your active child theme (or theme) and Save the file.

add_filter('wp_generate_tag_cloud', 'remove_tagcloud_inline_css',10,1); 
function remove_tagcloud_inline_css($input){ 
return preg_replace('/ style=("|\')(.*?)("|\')/','',$input); 
//return preg_replace("/style='font-size:.+pt;'/", '', $input); 
}

Leave a Comment

Scroll to Top