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
- How to use the do_action () with parameter
- TinyMCE custom styles remove class when switching styles
- Extending the site search to include a single custom field
- Notify users whenever a new post is published based on their preference
- syntax for remove_filter in parent theme with class
- Remove Header and Footer in iframe
- Redirect if not logged in?
- How to set global variables in template page?
- Setting featured image with function, 1 part not working
- Comments to only be seen by their author
- Remove function or filter
- options.php problem – data not saved
- Filtering posts by category name based on page’s slug
- adding custom classes for tables
- Load parent theme files before child theme functions.php
- CSS for menu item added via functions.php
- Default Gallery Edit/Template Editable?
- Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘greenday_head’ not found or invalid function name
- How to validate this deprecated function
- How can I modify all existing tags while keeping the urls themselves?
- Scripts not appending to element in AJAX call – why?
- Trigger a custom function when option are saved in admin area
- Functions.php – Cannot Modify Header Information SOLVED [closed]
- How would I add “edit profile” and “blog post” functions to front-end?
- shortcode help require
- How can I add a filter for specific categories on functions.php?
- Custom editor color palette colors are not appearing in the editor
- echo custom fields with AJAX
- wordpress get_post_meta give only first value
- Using multiple line variable inside a function?
- Determine if, within a post, you are on page 2 or greater – WordPress documentation circular
- Wp-query Order By problem
- Compare meta key to current date in pre get post
- Javascript not loading after the document ready
- Need to convert image url to a Base_64 data url with wordpress function..
- How do I display a date correctly that is stored in the database as a backwards 8 digit number from Advanced Custom Fields? [closed]
- Modify shortcode to work with custom post types
- How to hightlight all ancestor menu items of a child page NOT displayed in menu
- Fatal error: allowed memory size when after using enqueue_script
- How to apply the ‘current_page_item’ class to an archive page in `wp_list_pages()`?
- how can I add filter in specfic field in my website?
- functions.php pharse error on complete new install
- If has action not working as expected
- Update wp_postmeta table based on 2 keys
- Best practice to call a function from a button-link?
- Disable wordpress update notification
- How to customize archive widget only for cpt?
- some profile informations like youtube link doesnt seem
- Help using ShortCodes to style whole chunks of the post
- How to modify or override a core function (wp_star_rating)
- Is there is a way to check daily first login?
- Pagination not working on my archive page for a custom post type
- Remove Featured Images from Posts Older Than a Certain Date
- Home/Static Page View for Visitors pages after that should be restricted
- functions.php filters not applied in AJAX call
- Settings in functions.php used by a plugin
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- Adding result from PHP function into an input field
- Modifying Page-Links format
- PHP error in shortcode [closed]
- How to get variable from other function inside class function using add_action for Ajax call