I don’t do a lot of code snippets, but I figured someone might find this helpful.

WordPress DashiconsWhat’s Are WordPress Dashicons

dashicons.min.css is a set of icons used in the WordPress admin. Some themes load them on the front end (or maybe it is the default in the WordPress core, I don’t know).

We often use these icons as part of the admin area when building out custom post types (CPT); adding an icon makes the CPT look unique in the admin menu. WordPress provides a clean icon set, and we can usually find one that works well.

However, if you are not taking advantage of these icons on the front end of the website, then there is no reason to load them anywhere outside the admin/backend.

Why You Might Want to Disable Dashicons

If you’re doing web page speed optimization, you know that you should remove unused CSS, and you’ll notice that this CSS file is about 30KB in size, not massive, but there is no need to load it if you are not using it, right?

Disable Dashicons on the Frontend for Non-Logged-In Users Only

When I first removed dashicons.min.css by deregistering the style in my functions.php file, I noticed it broke my WordPress admin bar when logged in as an administrator. Dashicons on the front of the website do serve a purpose.

It’s not a massive deal on a site with only one administrator, but there is a convenience factor here, and no one likes to see something that appears broken. So, I used the following in functions.php to load it based on the user role. You’ll need to adjust the role capability to work within your site.

// remove dashicons
function wpdocs_dequeue_dashicon() {
	if (current_user_can( 'update_core' )) {
	    return;
	}
	wp_deregister_style('dashicons');
}
add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_dashicon' );