Add WordPress Custom Body classes (2020)

Add WordPress Custom Body classes (2020)

Author: GeoDirectory

Date: August 18, 2020 

Category: Plugin development

WordPress Custom Body classes

WordPress Custom Body classes are something any WordPress developer will need to deal with sooner or later.

Using a plugin for this would be overkill because in most cases all we need are a couple of lines of code.

So, how do we add WordPress Custom Body classes?

WordPress has both a body_class function and a body_class filter (hook).

The body_class function is used in themes to add the classes autogenerated by WordPress, to the body tag of your website.

This is how it is added to the header.php file of your theme:

<body <?php

World of WordPress is hosted by: Build Your Site on the Fastest WordPress Platform

With Rocket, your websites will be blazing fast, always protected, and supported 24/7 by our experts with over 17 years of experience.