Filter hook 'body_class'

in WP Core File wp-includes/post-template.php at line 866

View Source

body_class

Filter Hook
Description
Filters the list of CSS body class names for the current post or page.

Hook Information

File Location wp-includes/post-template.php View on GitHub
Hook Type Filter
Line Number 866

Hook Parameters

Type Name Description
string[] $classes An array of body class names.
string[] $css_class An array of additional class names added to the body.

Usage Examples

Basic Usage
<?php
// Hook into body_class
add_filter('body_class', 'my_custom_filter', 10, 2);

function my_custom_filter($classes, $css_class) {
    // Your custom filtering logic here
    return $classes;
}

Source Code Context

wp-includes/post-template.php:866 - How this hook is used in WordPress core
<?php
 861  	 * @since 2.8.0
 862  	 *
 863  	 * @param string[] $classes   An array of body class names.
 864  	 * @param string[] $css_class An array of additional class names added to the body.
 865  	 */
 866  	$classes = apply_filters( 'body_class', $classes, $css_class );
 867  
 868  	return array_unique( $classes );
 869  }
 870  
 871  /**

PHP Documentation

<?php
/**
	 * Filters the list of CSS body class names for the current post or page.
	 *
	 * @since 2.8.0
	 *
	 * @param string[] $classes   An array of body class names.
	 * @param string[] $css_class An array of additional class names added to the body.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/post-template.php
Related Hooks

Related hooks will be displayed here in future updates.