Add a custom class name to Wordpress body tag?

前端 未结 7 1582
忘掉有多难
忘掉有多难 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:37

    In case you're trying to add classes to the body tag while in the Admin area, remember to use the admin_body_class hook instead. Note that it's a filter which works slightly different since it passes a string of classes rather than an array, so your code would look like this:

    add_filter('admin_body_class', 'my_admin_body_class');
    function my_admin_body_class($classes) {
        return $classes . ' my_class';
    }
    

提交回复
热议问题