To enqueue CSS in WordPress you can use:
wp_enqueue_scripts
action for the frontendlogin_scripts
action for the login pageadmin_scripts
action for the admin side, as you already know
To check user’s roles you should get the user object and check the roles property. current_user_can()
is function intended to check capabilities, not roles.
So, to add CSS based on user roles in the frontend:
add_action( 'enqueue_scripts', 'cyb_enqueue_styles' );
function cyb_enqueue_styles() {
$user = wp_get_current_user();
if( ! empty( $user ) && count( array_intersect( [ "seller", "partner" ], (array) $user->roles ) ) ) {
wp_enqueue_style( 'my-style', get_template_directory_uri().'/some-style.css' );
}
}
Related Posts:
- How do i use fontawesome icons in TinyMce editor?
- Gutenberg Block Editor Match Admin Styles & Frontend Styles
- Deregister CSS style link ‘open-sans-css’
- Different css rules for TinyMCE and Gutenberg while using add_editor_style()
- Load in wp admin assets from child theme
- Admin pages missing css
- How to enable table overflow scroll? (especially order list table)
- How to disable the hover effect in WordPress and Elementor?
- How to stop my themes CSS changing the WordPress interface/?
- dynamic css file for admin / backend and get_option results in Uncaught Error: Call to undefined function get_option()
- Custom css author role
- Button doesn’t work in the profile panel
- ACF Gut block broke wordpress default style?
- WordPress Sudden Loss of All CSS And Tons of JQuery Errors
- How can I add a stylesheet to the Classic Editor page?
- Stop custom Gutenberg styles taking over other admin bits?
- Admin bar default color scheme for nonregistered/nonlogged users
- Lines of CSS only being delivered while logged in
- Adding custom css to a theme depending on whether the admin user is logged in or not
- Change Login CSS – Include instead of echo
- custom css in admin panel by user id
- Enqueue MCE Editor CSS in admin page
- How to change btn color in Bootstrap
- Failed to decode downloaded font, OTS parsing error: invalid version tag + rails 4
- force footer on bottom on pages with little content
- Dynamically change color to lighter or darker by percentage CSS
- How do I right align div elements?
- CSS “margin: 0 auto” not centering
- What is the difference between “screen” and “only screen” in media queries?
- How to have an anim gif on a link and play it on hover and reset
- Detect if a browser in a mobile device (iOS/Android phone/tablet) is used
- Using font awesome in codepen
- using media queries with LESS
- How can I apply styles to multiple classes at once?
- How to get multiple images to auto resize and stay centered within a div
- CSS rotation cross browser with jquery.animate()
- How can I center
- into a div?
- How to specify a class added to my gallery
- How to add a “last” class to the last post in loop.php?
- Assign title-specific class to list items in menu based on WP pages
- Load custom css after bootstrap
- Highlighting the current page in a navigation menu which links are generated with a custom loop?
- If I dequeue Gutenberg Stylesheet will that have any effect on WordPress 5.0.1?
- How to center a video [closed]
- Remove WordPress/Gutenberg button styles for ACF blocks
- Relative path instead of absolute for wp_enqueue_script
- Specific css on homepage, different one for other pages
- Media library style not loading correctly when selecting a page featured image?
- Using uncss or similar with WordPress?
- How can i add note, caution, warning quote inside the text? [closed]
- Add to Cart button woocommerce background and with doesn’t display correctly
- How to enqueue a random css style?
- How To Add a Transition style to WordPress Comment Box? [closed]
- What’s the best way to add the LESS preprocessor to a WordPress theme?
- How to use Japanese characters for a single page
- How do I make header.php use different css for different pages?
- How to change header dimensions in WordPress?
- How to display custom style based on theme option select box
- Implementing a simple slider in code?
- Target h1 on single post page [closed]
- Can not find css directory in header
- custom header navigation has odd spacing [closed]
- Error in node.js webpack-cli failed to load config, typeError: ManifestPlugin is not a constructor
- Append style tag in head while shortcode runs
- Add a unique body class for every admin page (including trash)
- Why would a theme writer put their CSS in one long string? [closed]
- How can I selectively insert a header for my shop page in woocommerce? [closed]
- WordPress Caption Formatting
- Child Theme style.css changes aren’t showing. Parent “style-less.css” over rides it, and won’t update
- The Global Styles missing
- Broken css on mobile phones only on https
- WordPress CSS completely broken on IIS
- Trying to hide HENTRY (Author Meta Data) from a Post ID
- Probleme d’emplacement
- Getting and setting CSS variables with JQuery in WordPress backend fails
- How to show address in one row?
- Set version number in child’s style.css file
- Need help removing block of white space between footer widgets and footer [closed]
- How to make a sidebar form show at the top of page on mobile?
- Logo Keeps Changing to the Default for Transparent Settings
- Custom Plugin CSS: Can’t update them!
- Head section of the wordpress blog
- Altering the design of WooCommerce notifications [closed]
- How can I add this specific link hover effect to a WP site? [closed]
- HTML5/CSS3 Polyfill for wp-login.php
- Bizarre WordPress CSS update problem
- Making a custom CSS per mobile
- Pages in another language
- Using a style sheet for modern browsers and another for older browsers
- How to insert a clickable and fixed background [duplicate]
- Will the following code make my css deal with images in the optimum way?
- Interactive maps in wordpress
- How to add input search field with roudned corners?
- s2member captcha how to make responsive – css or javascript
- Min height of page [closed]
- How to define a special character to change the style of my inline code?
- Why is the “Additional CSS” section missing in my theme Customizer?
- can i custom rendered content from API?
- How to include Elementor CSS in custom php file [closed]
- What is unsafe about this CSS?