2

A few days back I started working on re-optimizing my site to even great extent. While analyzing, I saw that WordPress dashicon files gets added to each page of my site but as we all use fontawesome now it is nothing but a waste.

So, I put the following code inside my functions.php file to deregister the dashicon files from the front end of my sites:

add_action( 'wp_print_styles', function() {
    wp_deregister_style( 'dashicons' );
}, 100);

Now after adding this into my site, everything seems working fine but when I enabled the admin toolbar to be shown on the frontend of the site, I saw that the toolbar is not showing properly and it is broken.

So, again after analyzing the problem I saw that this is happening due to the deregister of dashicons.

Now my question is why the front end admin toolbar is broken up as soon as I deregister dashicons? Is is because the way I'm doing it or something else?

Any explanation will be really helpful.

3

Well, the dashicons are used in the admin bar, so if you deregister them, your admin bar is broken. The easy way out is only to deregister the icons if there is no admin bar:

add_action( 'wp_print_styles', function() {
    if (!is_admin_bar_showing()) wp_deregister_style( 'dashicons' );
}, 100);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.