How to add a custom class name to WordPress body tag?

You are currently viewing How to add a custom class name to WordPress body tag?

How to add a custom class name to WordPress body tag?

To add a custom class name to the body tag in WordPress, you can use the body_class filter hook. This hook allows you to modify the classes that are applied to the body element.

Here’s an example of how you can use this hook to add a custom class name:

Copy codefunction add_custom_class_to_body($classes) {
    $classes[] = 'custom-class';
    return $classes;
}
add_filter('body_class', 'add_custom_class_to_body');

This code adds a new class called “custom-class” to the body element. You can replace this class name with any custom class name that you want to use.

You can add this code to your theme’s functions.php file or in a custom plugin. Make sure to save the changes and refresh your website to see the custom class name being added to the body element.

if you need any help in wordpress development click here

Leave a Reply