Change css for certain user roles

admin2025-01-07  3

I am trying to do a #tribe_events_event_options{display:none;} for all the author users on my site. I don't want them to be able to set an event to featured, and I thought the simplest way was to not display the box.

Is there an easy way to target user groups for custom css? I've made a author.css file in the child theme folder.

I found this post, but It did not do it for me. Custom CSS In Admin Only For Certain Roles

function wpa66834_role_admin_body_class( $classes ) {
global $current_user;
foreach( $current_user->roles as $role )
    $classes .= ' role-' . $role;
return trim( $classes );
}
add_filter( 'admin_body_class', 'wpa66834_role_admin_body_class' );

Writing css like: example

.role-editor #main-header {display:none;}

But the css is not affected. Am I missing something?

Thanks in advance!

I am trying to do a #tribe_events_event_options{display:none;} for all the author users on my site. I don't want them to be able to set an event to featured, and I thought the simplest way was to not display the box.

Is there an easy way to target user groups for custom css? I've made a author.css file in the child theme folder.

I found this post, but It did not do it for me. Custom CSS In Admin Only For Certain Roles

function wpa66834_role_admin_body_class( $classes ) {
global $current_user;
foreach( $current_user->roles as $role )
    $classes .= ' role-' . $role;
return trim( $classes );
}
add_filter( 'admin_body_class', 'wpa66834_role_admin_body_class' );

Writing css like: example

.role-editor #main-header {display:none;}

But the css is not affected. Am I missing something?

Thanks in advance!

Share Improve this question asked May 1, 2018 at 12:20 BlomshitBlomshit 13 bronze badges 3
  • Is it in the frontend or in wp-admin area? – mukto90 Commented May 1, 2018 at 15:38
  • Have you tried to !important to the css? .role-editor #main-header {display:none !important ;} – BenB Commented May 1, 2018 at 17:40
  • @mukto90 it's in the wp-admin area. I am trying to disable the "feature event" option in the The Events Calendar for authors as the editor should be the only one to make events featured. BenB I have tried "!important". The css seem to work for frontend, but not for the admin panel/events in my case. – Blomshit Commented May 2, 2018 at 16:29
Add a comment  | 

1 Answer 1

Reset to default 0

Your code seems to be correct maybe your selector is wrong? can you post the body html of your page that is outputed?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736252700a66.html

最新回复(0)