add class to body class wordpress

To add a class to the body element in WordPress, follow these steps:

  1. Navigate to your WordPress dashboard.
  2. Go to "Appearance" and select "Theme Editor."
  3. In the Theme Editor, locate the "functions.php" file on the right-hand side.
  4. Add the following code snippet at the end of the "functions.php" file:
function add_custom_body_class($classes) {
    // Add your custom class here
    $classes[] = 'your-custom-class';

    return $classes;
}
add_filter('body_class', 'add_custom_body_class');

Replace 'your-custom-class' with the desired class name.

  1. Save the changes.

This code creates a function named add_custom_body_class that appends your custom class to the array of body classes. The add_filter hook then applies this function to the body_class filter, ensuring that your custom class is added to the body element.

Now, when you view the source code of your WordPress site, you should see your custom class added to the body element.