body_class WordPress Filter Hook

The body_class hook is one of the most important hooks in WordPress. It allows themes and plugins to add classes to the body element of the page. This can be used to style specific pages or elements differently. It is also used by some plugins to add specific classes to the body so that they can target those elements with JavaScript or CSS.

apply_filters( 'body_class', string[] $classes, string[] $class ) #

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


Parameters

$classes

(string[])An array of body class names.

$class

(string[])An array of additional class names added to the body.


Top ↑

More Information

Note that the filter function must return the array of classes after it is finished processing, or all of the classes will be cleared and could seriously impact the visual state of a user’s site.


Top ↑

Source

File: wp-includes/post-template.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.