Performance PHP Beginner

Remove Dashicons When the Admin Bar Is Hidden

Stop WordPress from loading the Dashicons font stylesheet on the frontend for visitors who aren't logged in, since Dashicons is only needed for the admin bar.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 7 lines
add_action( 'wp_enqueue_scripts', function (): void {
	// The admin bar needs Dashicons, so keep them whenever it shows.
	if ( is_admin_bar_showing() ) {
		return;
	}
	wp_dequeue_style( 'dashicons' );
}, 100 );

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.

Dashicons is WordPress’s built-in icon font, used throughout the admin interface for menu icons, toolbar icons, and UI elements. WordPress also loads the Dashicons stylesheet on the front end of your site, because the admin bar, which appears for logged-in users, uses Dashicons for its icons. The problem is that WordPress loads Dashicons for every visitor by default, even those who are not logged in and will never see the admin bar.

For most sites, the vast majority of visitors are not logged in. They’re loading a stylesheet full of icons they will never need.

What the code does

It runs at priority 99, after all other scripts have been enqueued, and deregisters Dashicons entirely for non-logged-in visitors.

Why Deregister vs Dequeue

Using wp_deregister_style() rather than wp_dequeue_style() prevents Dashicons from being re-enqueued as a dependency. Some plugins enqueue their own stylesheets with Dashicons listed as a dependency, if you only dequeue it, those plugins can re-enqueue it. Deregistering removes it from the registry entirely so it cannot be loaded regardless of dependency declarations. This is appropriate for the frontend-only context where Dashicons genuinely is not needed.

Plugins That Use Dashicons on the Frontend

Some plugins deliberately use Dashicon classes for front-end icon elements, rating stars, social icons, or UI controls built with Dashicon characters. If any front-end element on your site stops displaying correctly after applying this snippet, it’s likely using a Dashicon character. The fix is to either inline the specific icon SVG used or load a lightweight alternative icon set for that component. Check your browser console for failed requests to the Dashicons font file to confirm this is the cause.

File Size Context

The Dashicons stylesheet is approximately 35KB minified, plus the associated woff2 font file at around 40KB. Removing it eliminates two HTTP requests and ~75KB of payload for every unauthenticated page view. On a site receiving thousands of daily visits, this is a meaningful reduction in bandwidth and rendering overhead.

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