The body_class hook seem only to work with non-admin pages. When I do

add_filter('body_class', 'add_body_classes');
function add_body_classes($classes) {
        $classes[] = 'myclass';
        return $classes;

Is there another hook i should be using if i want to add a class to the body of an admin page?

4 Answers 4


Admin pages don't use the body_class filter, use the admin_body_class filter to add classes to admin body tag instead.

Note that $classes in that case is a string, not an array.

  • 12
    It's worth noting that the $classes parameter in the method for the admin_body_class filter is a string and not an array developer.wordpress.org/reference/hooks/admin_body_class Commented May 25, 2016 at 16:30
  • I wish @Mamaduka would write that comment into the answer. I just tore down an entire site, before I noticed Romans comment.
    – Zeth
    Commented Nov 5, 2020 at 13:35

Mamaduka answer pointed me to the right direction, here is the code for adding classes to the body in the dashboard.

The callback function should return a valid value for the HTML class attribute, that is space separated class names, also, don't forget to prepend (or append) any existing classes, you should understand by reading the code.

add_filter( 'admin_body_class', 'my_admin_body_class' );

 * Adds one or more classes to the body tag in the dashboard.
 * @link https://wordpress.stackexchange.com/a/154951/17187
 * @param  String $classes Current body classes.
 * @return String          Altered body classes.
function my_admin_body_class( $classes ) {
    return "$classes my_class";
    // Or: return "$classes my_class_1 my_class_2 my_class_3";
  • 1
    This should probably be the selected answer. Asker's original implementation returns an array, but the hook accepts a space-separated string: https://developer.wordpress.org/reference/hooks/admin_body_class/. Selected answer is therefore misleading, as it only partially answers the question and provides no reference.
    – pwbred
    Commented Oct 2, 2015 at 19:30
  • To make PHP more easy to implement if you are not a programmer, without using strings inside doubble quotes are the same as return $classes.' my-class my-other-class'; Commented Jun 10, 2018 at 11:42
  • I use return sprintf('%s folded', $classes); as per my convenience. Commented Mar 14, 2019 at 6:27

Adding multiple classes, and especially when they must display based on some conditions, may result in an inconsistent HTML output. To format it correctly and also have the ability to remove duplicates or existing classes, we can convert them to array and in the end join back to string:

add_filter('admin_body_class', static function ($classes) {
    $classes = explode(' ', $classes);
    $classes = array_merge($classes, [

    return implode(' ', array_unique($classes));


one of the hooks i use for editing WP admin/Dashboard admin_head

    function remove_screen_options(){ 

    $hideCSS = '<style>#screen-meta-links { display: none; }</style>';


Will put the css in your admin part

And by using class .wp-admin you could style the body part of admin.

Good luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.