Add page slug as body class

Reader Interactions

Comments

  1. George Cleveland says

    Just thought your readers might be interested in a way to do this without writing custom code. There is a plugin call “WP247 Body Classes” that can add a myriad of classes to the body tag based on all kinds of conditions. In this case, you could simply check the box next to “is-page-(slug)” and “is-post-(slug)” on the “Post Classes” tab and save your settings. Once complete, your pages will contain “is-page-?” or “is-post-?” classes where “?” is the post slug. Then, using the same principle you have described, style the pages as is appropriate.

Leave a Reply

Your email address will not be published.