Add a custom class name to Wordpress body tag?

You can use the body_class filter, like so:

function my_plugin_body_class($classes) {
    $classes[] = 'foo';
    return $classes;
}

add_filter('body_class', 'my_plugin_body_class');

Although, obviously, your theme needs to call the corresponding body_class function.


You can also use it directly inside the WP body_class function which will append the string inside body class.

eg.

$class="custom-class";
<body <?php body_class($class); ?>>

http://codex.wordpress.org/Function_Reference/body_class

Tags:

Php

Wordpress