I don’t do a lot of code snippets but I figured someone might find this useful.
What’s Are WordPress Dashicons
dashicons.min.css is a set of icons used in the WordPress admin. Some themes load them on the frontend as well (or maybe it is the default in the WordPress core, I really 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 frontend of the website, then there is no reason to load them anywhere outside the admin/backend.
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. Apparently, dashicons on the front of the website do serve a purpose.
Not a huge deal on a site where there is 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 user role. You’ll need to adjust the role capability so it works 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' );
No matter how much you test a new website yourself, you won’t notice all bugs and things that need to...
FatLab, LLC is a proud Virginia, USA Corporation serving organizations throughout the United States and beyond. We pride ourselves on providing the best client-centric website support and website maintenance services possible. We have partnered with top-tier infrastructure and service companies to provide enterprise-level website security, WordPress hosting and monitoring solutions. We are huge fans and thankful for open source technologies.