Wordpress tag cloud: how to remove inline style for font size? Wordpress tag cloud: how to remove inline style for font size? wordpress wordpress

Wordpress tag cloud: how to remove inline style for font size?


You can use WordPress' core filters to modify output by different functions. wp_generate_tag_cloud() has a filter that allows you to edit the string input. Below is a function that regexs the string, finds the inline style and removes it.

add_filter('wp_generate_tag_cloud', 'xf_tag_cloud',10,3);function xf_tag_cloud($tag_string){   return preg_replace("/style='font-size:.+pt;'/", '', $tag_string);}


Unfortunately Rezens regexp didn't work in my case. You can use the following filter and regexp to remove the whole inline style tag on the output:

add_filter('wp_generate_tag_cloud', 'myprefix_tag_cloud',10,1);function myprefix_tag_cloud($tag_string){  return preg_replace('/style=("|\')(.*?)("|\')/','',$tag_string);}


If you inserting this with PHP, it doesn't help with removing the inline styles but you can set the 'smallest' and 'largest' parameters to ensure the font size is the same, see the Codex for more info on this.