Do you want to Add the custom class in body_class function to page templates in WordPress with the just simple code?
Then you land at the right place.
We have written the simple function code that will help you to easily add body_class to page templates.
Just follow the below steps:
Add body_class to Page Templates
First, you need to copy the below code and paste it into your WordPress theme’s functions.php file.
Code snippets for WordPress add body class
Change the template file name in the line no: 10 to your’s template name and change the CSS class name on the line no: 11 to whatever you want.
We have created the template for videos and named it videos.php file. Now we want to add custom body_class named “videos” on that template page.
So we would modify our code and it would look like below snippets:
Hope you understood this guide.
Let us know if you have any opinion or question in the comment box.
Don’t forget to share this add body class from page template