apply_filters( 'admin_body_class', string $classes )

Filters the CSS classes for the body tag in the admin.


Description

This filter differs from the ‘post_class’ and ‘body_class’ filters in two important ways:

  1. $classes is a space-separated string of class names instead of an array.
  2. Not all core admin classes are filterable, notably: wp-admin, wp-core-ui, and no-js cannot be removed.

Top ↑

Parameters

$classes string
Space-separated list of CSS classes.

Top ↑

Source

File: wp-admin/admin-header.php. View all references

$admin_body_classes = apply_filters( 'admin_body_class', '' );


Top ↑

Changelog

Changelog
Version Description
2.3.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Philipp Stracker

    When adding new classes to the body, you should make sure to add spaces before and after your class name. This prevents accidental concatenation of two plugins class-names.

    Example:

    function admin_body_class( $classes ) {
        // Wrong: No space in the beginning/end.
        $classes .= 'my-class1 my-class2';
    
        // Right: Add a leading space and a trailing space.
        $classes .= ' my-class1 my-class2 ';
    
        return $classes;
    }
  2. Skip to note 2 content
    Contributed by thejaydip

    If the current page is a post/page in edit mode

    function wpdocs_admin_classes( $classes ) {
    	global $pagenow;
    
    	if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
    		$classes .= ' your-class';
    	}
    
    	return $classes;
    }
    
    add_filter( 'admin_body_class', 'wpdocs_admin_classes' );

You must log in before being able to contribute a note or feedback.