6

Is there any way to remove the dashicons.min.css file from the frontend? I know that they are used by the admin panel, but my theme doesn't use them so it's an unnecessary request.

  • This stylesheet is not enqueued by default. A theme or a plugin enqueues it. – fuxia Sep 15 '14 at 21:10
16

Try deregistering that stylesheet -

add_action( 'wp_print_styles',     'my_deregister_styles', 100 );

function my_deregister_styles()    { 
   //wp_deregister_style( 'amethyst-dashicons-style' ); 
   wp_deregister_style( 'dashicons' ); 


}
  • Where did you try it? Try it in 'wp_print_styles' hook in functions.php – WisdmLabs Sep 15 '14 at 19:16
  • Yep, I added this to my functions.php. But wp_deregister_style and wp_dequeue_style doesn't work. – Slevin Sep 15 '14 at 19:44
  • 1
    wp_deregister_style('dashicons'); did the trick. – Slevin Sep 15 '14 at 19:53
  • 1
    OK, so that means the handle name is 'dashicons'. Let me update the answer, so that it should be helpful to others. – WisdmLabs Sep 16 '14 at 6:16
11

If you want to load dashicons only to admin user, try to put this into functions.php file:

// remove dashicons in frontend to non-admin 
    function wpdocs_dequeue_dashicon() {
        if (current_user_can( 'update_core' )) {
            return;
        }
        wp_deregister_style('dashicons');
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_dashicon' );
2

Here's my solution to this issue. It's similar to the ones proposed by WisdmLabs and JoseLazo above but it performs a better conditional check. The dashicons style is loaded for all logged-in users belonging to any role (and not just admins) as dashicons style is needed to properly display the frontend admin bar.

// Remove dashicons in frontend for unauthenticated users
add_action( 'wp_enqueue_scripts', 'bs_dequeue_dashicons' );
function bs_dequeue_dashicons() {
    if ( ! is_user_logged_in() ) {
        wp_deregister_style( 'dashicons' );
    }
}
0

use wp_dequeue_style. http://codex.wordpress.org/Function_Reference/wp_dequeue_style

it may be that some other style sheet is listing dashicons as a dependency, so if dequeueing doesn't work, check for that.

0

If you want to deregister css styles from your child theme's functions.php, I would suggest navigating the parent theme and search for the wp_enqueue_style() method applied for the style sheet you want to remove.

For e.g if you want to remove app.css in your child theme,

search for app.css in your parent theme and find the code that enqueues this style.

You may find something like

wp_enqueue_style('parent_theme_style', get_template_directory_uri() . '/assets/css/app.css', false, '2.2');

Now, in your functions.php for your child theme, add the following snippet :

add_action( 'wp_print_styles', 'my_deregister_styles', 200 );

function my_deregister_styles() { 
    wp_deregister_style('parent_theme_style');
    }

The catch is that wp_derigster_stlye('app') won't work here.

This is a small issue that some people might miss and hence posting it here.

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.