How to Add Page Slug in Body Class of your WordPress Themes


How to Add Page Slug in Body Class of your WordPress Themes
Stella Morris

If you work on WordPress themes on a regular basis, then it is probably best to familiarize yourself with these default WordPress generated CSS cheat sheet. Recently while working on a custom theme project, we found a need to customize certain items based on different pages. WordPress has these things called body classes which outputs the class page, page-template-{filename} and page-id-{number}. We couldn’t use page-id-{number} because page IDs change from development to deployment. We also didn’t want to create a custom page template with repetitive code. 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.

How to Add Page Slug in Body Class of your WordPress Themes
Tasha Martin

As we know that many times,we need to get the search post by title only .Actually we need the exact and accuracy result in our search functionality. Why would you want to do that? Actually every user’s (Approximately) need the only desire result…

Adding to the Body Class in WordPress
Laurie Castro

It’s possible to use a WordPress filter to add a body class, too. This method keeps the theme code cleaner and is particularly useful if you want to add a body class from a plugin. This code can either go in your themes functions.php or within your plugin.

Be the first to comment

Leave a Reply

Your email address will not be published.


*