Last active
January 15, 2022 19:34
-
-
Save jancbeck/3178689 to your computer and use it in GitHub Desktop.
WordPress: Add user role class to body tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add role class to body | |
function add_role_to_body($classes) { | |
foreach (wp_get_current_user()->roles as $user_role) { | |
$classes[] = 'role-'. $user_role; | |
} | |
return $classes; | |
}); | |
add_filter('body_class','add_role_to_body'); | |
add_filter('admin_body_class', 'add_role_to_body'); | |
?> |
Thank you @tedw it works great!
HELLO
I am beginner! Pltease help!
I need the snippet, which will hide the button ADD LISTING for couple roles
Please help I don't understand
I download and install "Code Snippets"
For test I take the code from the first messages of this discussion
I need make 2 snippets for two different roles
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Agreed, I used the first snippet posted by @tedw and it works perfectly on the frontend. Don't really need the role as body classes on my WP Admin.