Site logo

[Resolved] Adding CSS selector form (for custom body class) on individual page/post

Home Forums Support [Resolved] Adding CSS selector form (for custom body class) on individual page/post

Home Forums Support Adding CSS selector form (for custom body class) on individual page/post

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2510473
    Mark Corpuz

    Question:
    1. Does GeneratePress have the option to add custom body class when editing a page/post?
    2. If NOT, what’s your recommendation on how I can implement manually doing this (possibly using custom fields or acf)?

    For context: I transitioned from the Genesis Framework where you have a simple form that allows you to insert CSS selector into the overall body class of that existing page/post.

    The benefits of being able to add CSS selectors unto the page/post is to provide us with the freedom to make simple “preset” css selector changes on the layout of the site without having to add unique styles via an “element”. I really hope you have this as a future feature (assuming you don’t have it yet).

    #2510489
    Fernando
    Customer Support

    Hi Mark,

    There’s no setting for this, but there is a way.

    Specifically, there’s a WordPress filter you can use for this. Reference: https://docs.generatepress.com/article/add-a-custom-class-to-the-body-element/

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    #2510909
    Mark Corpuz

    Thank you for the suggestion you made. That definitely pointed me towards the right direction. I’m not a php programmer but I’m familiar with the fundamental concepts to recognize my options.

    Therefore, I submit this free plugin as my recommendation:
    https://wordpress.org/plugins/add-custom-body-class/#description

    In all things GeneratePress, my goal is to be as minimal as possible with code. Hence I wanted to get your opinion based on the copied plugin code below if all of these are necessary.

    https://gist.github.com/markcorpuz/43ad1ec861e7f7d1cecd4fe8de8fe54a

    My goals are simple:
    1. Display a simple form on page / post editor allowing me to enter a css selector
    2. Insert (or append) that css selector with Gutenbergs default selector

    And while this topic is technically resolved, I would still want to get you opinion on the plugins code to see what code can be copied to be as minimal as possible to accomplish the same goal.

    #2511378
    Ying
    Staff
    Customer Support

    Hi Mark,

    I’m sorry but we can’t examine codes from a 3rd party plugin for you.

    Have you tried Fernando’s code? If you are not comfortable editing code, then you’ll have to use a plugin.

    #2512364
    Mark Corpuz

    It’s okay. You’re solution is a pretty good option. I appreciate it. Consider this topic resolved.

    #2512390
    Ying
    Staff
    Customer Support

    Glad to hear that 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.