How to create a custom body class in PHP?

How to create a custom body class in PHP?

If your theme doesn’t include a body class field built in, you can add this code with the parameter you want to use to your header.php file. You’ll then need to add a custom function as well. Simply paste this code in your child themes functions.php file and add your new body class to a specific page.

Where do I find the custom body class in thesis?

Located in your Layout settings on all Edit Post/Pages. Note: Custom classes cannot start with a number. Thesis already creates a body class for pages (not posts) including pages for archives and categories. You can grab the auto generated body class for pages from the source code.

How does the Custom Class Selector work in CSS?

The custom class selector enables you to style all HTML elements with the same CSS code for that specific page or post only. Elements outside of the content area, like your footer, header and sidebar, will not be effected by the CSS code you apply to this custom class.

How do I add a class to my body in WordPress?

The body_class () function in WordPress makes this very easy for us by automatically adding a bunch of appropriate classes to the body tag of our website. One such example would be the logged-in class that is added to the body tag if a logged-in user is viewing the page.

When to use custom body class and custom post class?

The Custom Body Class and Custom Post Class fields can be used to add a class name of your choice to either of these fields to help you style your pages and posts. The Custom Post Class applies only to the content in the editor or content area; it will not affect the sidebars or footer.

How to get body class in WordPress theme?

The actual HTML output might resemble something like this (the About the Tests page from the Theme Unit Test): In the WordPress Theme stylesheet, add the appropriate styles, such as: echo ‘class=”‘ . esc_attr ( implode ( ‘ ‘, get_body_class ( $class ) ) ) .

How to add page slug in body class of your WordPress themes?

We knew that we can keep one thing the same on all of these pages which were page-slugs, so we decided to add page slugs in body class which allowed us to do all the customizations we wanted without any complications. In this article, we will show you how to add page slug in body class of your WordPress themes.