Opened 8 years ago
Closed 8 years ago
#40924 closed feature request (maybelater)
Making font_size data for wp_generate_tag_cloud_data filter more flexible
| Reported by: |
|
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_argsfilter ( see the source below )/** * Filters the taxonomy used in the Tag Cloud widget. * * @since 2.8.0 * @since 3.0.0 Added taxonomy drop-down. * @since 4.9.0 Added the `$instance` parameter. * * @see wp_tag_cloud() * * @param array $args Args used for the tag cloud widget. * @param array $instance Array of settings for the current widget. */ $tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => $current_taxonomy, 'echo' => false, 'show_count' => $show_count, ), $instance ) );You may be able to achieve what you're looking for by adding the filter above and setting
unitas empty and then filtering thefont_sizeto beunsetusing thewp_generate_tag_cloud_datafilter.I'm going to close this out as a
maybelaterbut @westonruter if you feel different, feel free to reopen.