Created
February 19, 2016 20:08
-
-
Save smeric/2a9b21f37887f2e56805 to your computer and use it in GitHub Desktop.
Add user roles as classes to body tag in front and backend.
This file contains hidden or 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 user roles as classes to body tag in front and backend. | |
*/ | |
add_filter( 'body_class','add_roles_to_body' ); | |
add_filter( 'admin_body_class', 'add_roles_to_body' ); | |
function add_roles_to_body( $classes ) { | |
global $current_user; | |
foreach ( $current_user->roles as $user_role ) { | |
// body classes are built differently on the front and back end. | |
// https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-admin/admin-header.php#L164 | |
if ( ! is_admin() ) { | |
$classes[] = 'role-'. $user_role; | |
} | |
else { | |
$classes .= 'role-'. $user_role; | |
} | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment