Site logo

Archived topic

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

5 replies · Started by Mark Corpuz on January 26, 2023

Viewing posts 1–6 of 6

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).

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.

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.

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

Glad to hear that :)

This archived topic is closed to new replies.