Performance PHP Beginner

Remove the Recent Comments Widget’s Inline CSS

Stop WordPress printing a block of inline CSS in the page head for the classic Recent Comments widget.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 1 lines
add_filter( 'show_recent_comments_widget_style', '__return_false' );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

When the classic Recent Comments widget is active, WordPress prints a small style block in the head of every page to fix an old layout quirk. Most themes style the widget themselves, so it’s redundant.

How it works

WordPress checks show_recent_comments_widget_style before printing the .recentcomments a style. Returning false skips it.

Things to watch

  • This only matters if you use the classic Recent Comments widget. The Latest Comments block doesn’t add this CSS.

How to test it

View the page source and search for .recentcomments a. It should be gone.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only