WordPress – How to remove inline front-size style from tag cloud widget

The following WordPress PHP function will automatically remove the inline style from the tag cloud widget.

By default the tag cloud includes inline style that sets the font size of the tag, adjusting the size depending on how often it’s used.

However, this often does not look nice on a website – and is overwritten – becoming redundant HTML.

If you’re not sure where to place this code I highly recommend you read How to create a WordPress plugin for your custom functions.

// remove inline style from tag cloud widget

add_filter( 'wp_generate_tag_cloud', 'itsg_remove_inline_style_tag_cloud', 10, 1 );

     function itsg_remove_inline_style_tag_cloud( $tag_string ){
          return preg_replace( '/style=("|\')(.*?)("|\')/','', $tag_string );