Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at

RSS Latest posts from my personal blog

Most viewed posts

Subscribe to RSS feed

Add user role to admin body classes in WordPress

Stanislav KhromovStanislav Khromov


add_filter('admin_body_class', function($classes) {
    global $current_user;

    if(is_array($current_user->roles)) {
        foreach($current_user->roles as $role) {
            $classes .= "user-role-{$role} ";

    return rtrim($classes);

Classes will look like this:

<body class="... user-role-administrator ...">

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
Twitter Profile
Visit my other blog

Comments 2
  • John
    Posted on

    John John

    Reply Author


    It only work when editing a post.
    How to put this class in entire admin area?


  • iLen
    Posted on

    iLen iLen

    Reply Author

    Thank you, it was very useful.