Reputation: 343
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?
Upvotes: 1
Views: 579
Reputation: 785
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
Upvotes: 2