Opened 8 years ago
Closed 7 years ago
#40924 closed feature request (maybelater)
Making font_size data for wp_generate_tag_cloud_data filter more flexible
Reported by: | mhmdshv | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7.5 |
Component: | Widgets | Keywords: | 2nd-opinion |
Focuses: | Cc: |
Description
Hi,
The 'wp_generate_tag_cloud_data' filter currently supports font_size, but the flexibility is so little.
This data only accepts a number, and automatically appends a pt to it, setting the font's size. So for example if i set the font size by using the following code:
add_filter( 'wp_generate_tag_cloud_data', function( $tag_data ) { return array_map ( function ( $item ) { $item['font_size'] = '8'; return $item; }, (array) $tag_data ); } );
The result would be font-size:8pt . But if i want to unset the font size or for example use em/px, i won't be able to, unless i use preg_replace:
add_filter('wp_generate_tag_cloud', 'filter_tag_cloud',10,1); function filter_tag_cloud($string){ return preg_replace("/style='font-size:.+pt;'/", 'tyle='font-size:unset;', $string); }
This feature will come in handy in some theme's that have their own way of styling and handling the tag cloud widget. I for example, have problem with this in two of my theme that are being developed, since the font size is having a bad effect on my theme's appearance.
Here is a post on WordPress Stackexchange that we discussed this matter a bit further:
https://wordpress.stackexchange.com/q/225693/94498
Would love to see this in future.
Regards, Jack
@mhmdshv thanks for the reporting and welcome to WordPress core!
It is currently possible to apply a filter to change the unit type using the
widget_tag_cloud_args
filter ( see the source below )You may be able to achieve what you're looking for by adding the filter above and setting
unit
as empty and then filtering thefont_size
to beunset
using thewp_generate_tag_cloud_data
filter.I'm going to close this out as a
maybelater
but @westonruter if you feel different, feel free to reopen.