• Hi there,
    I’m hoping someone else has seen this issue before. I built a theme for a client about 6 months ago. Virtually every page on the 20+ page site has a custom layout and uses the template body class format “page-template-{directory}{filename}-php” for styling.

    Recently, they’ve been making updates to plugins and a couple of pages now have broken styles. I looked into this and found that the body class used for styling is no longer being generated. Other classes are still present generated, so generic site styles are working fine, but that specific class is missing (again, only from 2 out of 20+ pages).

    I updated plugins on my local environment and expectedly, I start getting the same problem on my environment. So, the next step, in my mind is to deactivate everything and start re-activating one at a time to find the issue. However, when I deactivate everything, the issue is still there. So, I remove the plugins folder from the project altogether. No change.

    Seemingly, something has happened to the WordPress installation from a plugin update that has caused the body_class() function to malfunction. But, I have no idea how to troubleshoot this, if the problem stays after removing ALL plugins. Any ideas? Is this something that could be from a recent WP update?

    Any help would be much appreciated! Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Digico Paris

    (@digico-paris)

    Hi,

    Sorry to ask, if you use Chrome Inspector Tools or Firefox Webdev to check code for

    <body class="style1 style2">

    Do you see any break in tags or something that breaks the 2 following classes?

    If not, I could suggest to avoid that by trick, using something like

    <body id="style1" class="style2">

    >>> that way you avoid the possible double class in same block issue. I had that with php/Jquery once.

    Have a nice day,

    Thread Starter justinmaurerdotdev

    (@360zen)

    I think I may have a solution here, but I’d still like some input.

    I can’t say I completely understand why some templates are behaving differently from others, but here’s what I’ve figured out.
    When using a custom template (assigned on the Page editing screen), WordPress generates a body class in this format: page-template-{directory}{filename}-php. Our styling is based on this format: page-template-{filename}-php. All of our page templates are stored within a /pages directory, so the class generated doesn’t match the class we’ve used for styling (BUT ONLY ON 2 PAGES?!). On all other pages, WP seems to be generating the wrong classes based on our file structure (page-template-{filename}-php w/o the directory name)
    So, I see two possible solutions.
    1) Move all templates (or at least the offending ones) from /pages/ to the root folder of the theme. Each template will need to be reassigned on the page edit screen.
    2) Add the correct classes to all css for the current setup. So, where ‘.page-template-my-template-php’ appears, we would add ‘.page-template-pagesmy-template-php’ (and ideally add that format for every other page-template class).

    Like I said, I’m still trying to wrap my head around why some of them behave one way and others behave another way, but I’m almost positive the above fix will solve our issue. I like option 1 better, as it doesn’t require code changes, just a file structure change and some WP admin work.

    Any thoughts about why this behavior seems inconsistent in WordPress?

    Thread Starter justinmaurerdotdev

    (@360zen)

    @digico, I’ve checked, and I don’t see any broken or duplicated classes. Thanks for the suggestion though.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page template body class not working after updates’ is closed to new replies.