- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by
Ying.
-
AuthorPosts
-
January 26, 2023 at 4:45 pm #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).
January 26, 2023 at 5:25 pm #2510489Fernando 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
January 27, 2023 at 4:27 am #2510909Mark 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/#descriptionIn 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 selectorAnd 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.
January 27, 2023 at 10:50 am #2511378Ying
StaffCustomer SupportHi 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.
January 28, 2023 at 1:00 pm #2512364Mark Corpuz
It’s okay. You’re solution is a pretty good option. I appreciate it. Consider this topic resolved.
January 28, 2023 at 1:14 pm #2512390Ying
StaffCustomer SupportGlad to hear that 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.