deazulturquesa
10/11/2019 - 12:35 PM

Cargar CSS según rol de usuario

Ejemplo de uso // añadir user-role-(rol)

`.logo { background: url(http://example.com/logo.png) no-repeat; }

.user-role-author .logo { background: url(http://example.com/logo-for-authors.png) no-repeat; }

.user-role-editor .logo { background: url(http://example.com/logo-for-wholesale_customers.png) no-repeat; }`

add_filter( 'body_class', 'add_role_to_body_class' );
function add_role_to_body_class( $classes ) {
    $current_user = wp_get_current_user();
    $current_role = (array) $current_user->roles;

    if( $current_role[0] ){
        $classes[] = 'user-role-'.$current_role[0];
    }

    return $classes;
}