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

4

7

Is there a nice way to remove the inline style from wordpress tag cloud tags? I'd like to set the same size for all tags and do not want inline styles at all if I can help it.

Thanks

Hookworm answered 26/5, 2011 at 12:9 Comment(0)
B
8

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);
}
Beaumont answered 17/7, 2012 at 18:20 Comment(0)
T
5

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);
}
Tarango answered 17/11, 2017 at 11:4 Comment(1)
This code works pretty well for me. It's what i looking for. Thank you!Constriction
H
1

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.

Hagio answered 26/5, 2011 at 22:43 Comment(0)
P
0

If you don't want to change your theme's code you can add a css font-size rule adding !important, it should override inline style.

Pericycle answered 26/5, 2011 at 22:29 Comment(1)
I DO want to change the theme's code! Is there a way to do it? I already have the tags looking how I want them with CSS, just wondering if I can remove all inline stye nonsense from my theme...Hookworm

© 2022 - 2024 — McMap. All rights reserved.