Make WordPress Core

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's profile 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

Change History (1)

#1 @welcher
7 years ago

  • Keywords 2nd-opinion added
  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

@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 )

/**
 * 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 unit as empty and then filtering the font_size to be unset using the wp_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.

Note: See TracTickets for help on using tickets.