apply_filters( 'body_class', array $classes, array $class )

Filters the list of CSS body classes for the current post or page.

Description Description

Parameters Parameters


(array) An array of body classes.


(array) An array of additional classes added to the body.

Top ↑

Source Source

File: wp-includes/post-template.php

View on Trac

Top ↑

Changelog Changelog

Version Description
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Drew Jaynes

    Remove Classes

    Remove an existing body class by un-setting the key from the $classes array.

    // Removes a class from the body_class array.
    add_filter( 'body_class', function( $classes ) {
    	if ( isset( $classes['class-to-remove'] ) ) {
    		unset( $classes['class-to-remove'] );
    	return $classes;
    } );
  2. Skip to note 2 content
    Contributed by Drew Jaynes

    Add New Classes

    You can add additional body classes by filtering the {@see ‘body_class’} hook.

    To add the following to the WordPress Theme functions.php file, changing my_class_names and class-name to meet your needs:

    // Add specific CSS class by filter.
    add_filter( 'body_class', function( $classes ) {
    	return array_merge( $classes, array( 'class-name' ) );
    } );

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