This is what I use, tested and works…
function wpse_admin_styles(){
$user = wp_get_current_user();
if( !empty($user) && count(array_intersect(["administrator"], (array) $user->roles ))) {
wp_enqueue_style(
'admin_css',
get_stylesheet_directory_uri() . '/css/admin-styles.css', array(), filemtime( get_stylesheet_directory() . '/css/admin-styles.css')
);
}
}
add_action('admin_enqueue_scripts', 'wpse_admin_styles');
Related Posts:
- Apply custom role capabilities to administrator (without plugin)
- Roles & capabilities GUI that does not create separate table
- How do I redirect upon login a specific user based on role?
- How to add another user to this remove_menu function?
- Add a new subscriber role using a function
- How to test for Super Admin
- Custom roles can’t access to wp-admin
- Custom registration URL lost when user makes signup mistake
- Custom function for specific user role
- Hide Author.php template from specific user role
- edit role display name and label name without plugins
- create shortcode to list users with specific meta key value
- Toggle User Roles with button
- How to change or add user role after getting post request data about pay? [closed]
- Execute a ultimate member action when user role is updated
- Allowing users to view private posts (pending approval)
- Allow Contributor to edit their own posts after Adm aproval
- How to add custom JavaScript in functions?
- How to set default post editor based on role?
- Adding additional roles on registration
- The Capability to choose post/page template
- How to add array [closed]
- Get users with different roles and call function on each of them (user_meta)
- How can I show different content for different user-levels?
- Custom user role still showing up after deletion, ideas?
- How to load a css file depending on the current role
- Allow user select role in wordpress default registration without plugin
- Remove check boxes and its label from screen option for custom role
- Add Change role button for list of user in an event
- How to show only specific category post by user role without plugin and restrict all other cats
- Change user role based on total number of items ordered
- Remove all video attachment, both files and post/postmeta from database?
- delete_user_meta for user in spesific group
- Change the second role depending on the first
- Restrict certain roles registrations by domain
- Multisite Admin Roles
- add_role menu pages are not visible
- Welcome Mails based on user role
- Get all users from role and add to dropdown (select) – wordpress, javascript
- Would it be possible to disable embeds for specific user roles? If so, how?
- How to make my logged-in user-role shortcode displaying name instead of slug?
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- One Child Functions.php for Multiple Child Themes
- Disabling pingback and trackback notifications
- register_post_type for Pages?
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How to get comments with mixed status using get_comments?
- How can I rename the WordPress AJAX URL? [duplicate]
- How to add a rel attribute to images that contains their categories?
- Is it possible to be more page/post specific with admin_enqueue_script?
- What is the most efficient method for loading widgets in functions.php
- Enqueue script o style only if a template part is loaded
- Can I pass two roles to the function get_users?
- Add external js file to footer with id
- How can I enable uploading excel files?
- Change the HTML of the comment form that is generating somewhere from the core WordPress
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- Twentyten Child Theme: header images display messed up in admin panel
- Removing wp_login_viewport_meta
- Move Custom Fields on General Settings Page to New Location
- How can I add a filter for specific categories on functions.php?
- Custom editor color palette colors are not appearing in the editor
- Set Taxonomy based on post status
- Is There Any Built In WP Functionality For Combining Form Fields To Return Specific Data
- wp_create_category deprecated?
- WordPress Excerpt – How to remove the first link using functions.php
- Sortable column (by numbers) in admin users
- How can I add a class to a nav li depending on URL?
- Compare meta key to current date in pre get post
- Is there a built-in function to duplicate existing posts?
- Filter to wp_list_authors
- Contact Form 7 If Condition
- Add Adsense code between job listings – wp job manager plugin
- How can I change the size of the text in Word Press
- Using depth=n in wp_list_pages
- shorthand syntax for custom fields
- Show admin page, only if function is being used
- Show errormessages on wrong username/password on custom loginform?
- How to apply the ‘current_page_item’ class to an archive page in `wp_list_pages()`?
- Class parameter in get_avatar args doesn’t get added to output
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- locking content with overlay/pop up ads
- How to use `foreach()` in ajax call
- Remove Featured Images from Posts Older Than a Certain Date
- Mail function not working with user accounts
- Function not recognizing page id?
- Conditionally write open graph meta property in header
- Using array page name together with page id to deregister script
- Modifying Page-Links format
- Give a function a unique ID
- how to handle multiple forloop?
- Text before price on WooCom
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Change Post status based on custom field date +1 day
- How to add height and width dimensions automatically to archive descriptions
- How to store page-{id}.php templates in custom folder
- Custom Admin Menu Report for Specific User ID
- How to cache results of of get_available_post_statuses() function as it is causing a slow query on a website with over 1 million posts?
- post_content return zero!