• Resolved Orbit Storm

    (@orbit-storm)


    This may be a bit complex, so forgive me.

    I’m looking to override a specific CSS class on a specific page. To be more specific, I have a tabs & accordions widget on an About Us page that I’d like to change up (style wise). I do not want to override the default class as it would affect the widget on other pages as well.

    After doing some extensive searching, the closest possible solution I’ve come across is body_class() but that seems more intended for overriding the CSS on an entire page rather than a specific portion of the page. The article I read on body_class() is located here.

    Perhaps I’m not interpreting body_class() appropriately but I cannot seem to locate a solution for this. Any help would be greatly appreciated!

Viewing 6 replies - 1 through 6 (of 6 total)
  • that seems more intended for overriding the CSS on an entire page rather than a specific portion of the page.

    Actually the classes generated by the body_class() function were designed specifically for this kind of situation and allow you to target your CSS at specific pages, post etc etc.

    The PHP code of your page doesn’t “control” the CSS styles, it just adds the relevant classes in that let you decide what you want to do with each page.

    For your example, something like this is what you’d need to do. Please keep in mind that this is a (very) simplified example.

    Standard page:

    .my_div {
       color: #000000;
    }

    Target one page only (this goes after the site-wide code):

    .page-id-123 .my_div {
        color: #FF0000;
    }
    Thread Starter Orbit Storm

    (@orbit-storm)

    Thank you both for the responses.

    For your example, something like this is what you’d need to do.

    When you mentioned using page id’s in your example, I remembered seeing something about applying a body class to specific pages, HERE. It’s essentially the same thing you offered, catacaustic, just much “cleaner”.

    Problem is, I haven’t a clue where to insert the bit of code the author is sharing (perhaps inside the header in header.php?). His original source, which likely contained a more in-depth tutorial, is no longer available.

    Forget about the code in that article. It’s 6 years out of date! Using the body_class(), the classes are all generated for you. See https://codex.www.ads-software.com/Function_Reference/body_class for a full list.

    Thread Starter Orbit Storm

    (@orbit-storm)

    Ha! Should have noticed the date as well. My apologies. Thank you for the updated link. Surprised that didn’t pop up in my Google search. Then again, I probably wasn’t using the best search parameters.

    That said, thank you both (immensely) for the prompt and useful responses. Issue solved, and will mark this topic as such.

    No problem. It’s what we’re here for. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Override CSS Class on specific page’ is closed to new replies.