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

Is there a good way to remove inline style from wordpress tag cloud tags? I would like to set the same size for all tags and generally do not want inline styles if I can help.

thank

+3
source share
4 answers

You can use basic WordPress filters to change the output using various functions. wp_generate_tag_cloud()has a filter that allows you to edit line input. Below is a function that redefines a 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);
}
+6
source

PHP, inline, " " " " , , . Codex .

+1

If you do not want to change your theme code, you can add a css font size rule, adding !importantit should override the inline style.

0
source

Unfortunately rezens regexp does not work in my case. You can use the following filter and regexp to remove the entire inline style tag in 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);
}
0
source

All Articles