With this snippet you add the page slug as a body class. If the page slug is for example contact, the extra body class is being outputted like this page-contact.
Add the snippet below to your theme’s functions.php
With the new body class you can override the default styles or style elements for specific pages.
If you want to have a dark footer on your contact page your css looks like this:
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.