Wordpress - How to remove dashicons.min.css from frontend?
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' );
}
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' );
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' );
}
}