I want to work on my style.css file. But It would be better if after all change and test I publish it for users. So Is there any way to make another style.css which load just for admin user?
1 Answer
You need to check the logged in user role before queuing it. So the code should be like bellow. you need to replace the plugins_url( 'my-plugin/css/plugin.css' ) with your stylesheet's path
function register_only_for_admin_styles() {
if( current_user_can('editor') || current_user_can('administrator') ) {
wp_register_style( 'admin-style', plugins_url( 'my-plugin/css/plugin.css' ) );
wp_enqueue_style( 'admin-style' );
}
}
add_action( 'wp_enqueue_scripts', 'register_only_for_admin_styles' );
Try the code then let me know the result. Thanks
3 Comments
joei
thanks, man. I edited it to ` wp_register_style( 'admin-style', get_template_directory_uri() . '/my-style.css', false, '1.0.0' );` and then it works.
joei
but another problem appears! When I disable some CSS from my-admin-style, it comes back, because the main style loads too. @souvik-sikdar
Souvik Sikdar
Do you want to load the admin-style only for admins?