• Resolved Jaja..

    (@jaja-1)


    How can we clean up the body class?

    I like to style lots of pages by CSS but when making different page templates i get strange body classes and most of them i can’t do anything with.

    <body class="page page-id-5 page-template page-template-page-php">

    This is the body class of my disclaimer template.

    While i have made custom template files for this page.
    like this.
    page-disclaimer.php
    content-page-disclaimer.php

    It would be cool if WP prints something like this.

    <body class="page page-id-5 page-disclaimer">

    Yes i could use the page-id-5 class but when you’re building and testing offline and working online page ID’s never end up on the same level.

Viewing 2 replies - 1 through 2 (of 2 total)
  • All of those classes are relevant.

    Perhaps most importantly for your use case, you’re missing the most important body class of all: page-template-page-php. That class is a page-template-specific class.

    It also tells me that, while you have created custom page templates, you haven’t actually applied them to the static page in question, because it’s using the page.php template.

    If you had applied the page-disclaimer.php template to the page in question, then that body class would be page-template-page-disclaimer-php, which you could then target via CSS, to apply custom styles to that page.

    So, a couple questions:

    1) Are you sure you’ve created your custom page templates properly?
    2) Are you sure you’ve applied your custom page template to the static page in question?

    Thread Starter Jaja..

    (@jaja-1)

    You’re right! Thanks for the heads up.

    What i did was create the page template applied it to the page.

    And after that i changed the name of the template file so WP switched it back to the default page template :S

    Sorry.. Stupid of me not seeing this happen.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Clean up the Body class?’ is closed to new replies.