Add a custom class name to Wordpress body tag?

前端 未结 7 1597
忘掉有多难
忘掉有多难 2021-02-07 03:29

I\'d like to place a directive in my theme\'s functions.php file which appends a classname to the wordpress body tag. Is there a built-in API method for this?

For exampl

7条回答
  •  醉梦人生
    2021-02-07 03:38

    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.

提交回复
热议问题