I've created following function to run a stylesheet for the admin area, but I want to runt it only for 'shop_manager' this user role and for others, it should not make any modifications from that stylesheet.

// Update CSS within in Admin
function admin_style() {
    if (current_user_can( 'administrator' ) ) {
        return admin_style();
  wp_enqueue_style('admin-styles', get_stylesheet_directory_uri().'/admin.css');
add_action('admin_enqueue_scripts', 'admin_style');

Problem with it is, when I put shop_manager in user role section it loads only shop_manager's admin dashboard and not the Administrator's. And when I add ! current_user_can it happens the same but vice versa. Please help!!

  • Thanks for providing the sample code you are using. It looks like you have a recursive function in there so behavior is probably not what you expect. Instead of returning admin_style(), shouldn't you be returning false or an empty string or something? I'm struggling to understand your intentions with this code. Commented May 21, 2019 at 10:41
  • Thanks and sorry my bad that I didn't return blank (false), now I remove admin_style() and write only return; and it worked. Commented May 21, 2019 at 10:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.