Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class to body tag for page slug #308

Open
smtierneybu opened this issue Jul 17, 2023 · 2 comments
Open

Add class to body tag for page slug #308

smtierneybu opened this issue Jul 17, 2023 · 2 comments

Comments

@smtierneybu
Copy link

Automatically include the page / post title (as slug) in the body classes.

This will allow further customization on front-end for specific pages.

We need to first research to see if this is already happening, and if not implement a solution that will be non-destructive in every way.

@roytfrank
Copy link
Collaborator

roytfrank commented Jul 17, 2023

@smtierneybu

After investigating, it appears that the page slug is not yet being added to the body class. Working on the implementation, Wordpress provides a filter hook called "body_class" which returns the body tag classes for a page. By adding this filter hook to your website, the page slug can be added to the body tag classes as implemented in the branch feature/add-page-slug-to-body-classes

roytfrank added a commit that referenced this issue Jul 18, 2023
roytfrank added a commit that referenced this issue Jul 18, 2023
@desrosj
Copy link
Contributor

desrosj commented Jul 21, 2023

I'd like to advise against using the slug as a body class, especially if specific styles are being assigned to it. Slugs are volatile and can potentially change unexpectedly (say when the title changes).

WordPress adds a body class for page-id-## and postid-## where ## maps to the IDs. By default, custom post types do not get the same treatment, though I seem to remember working on something like that somewhere in responsive-framework or a plugin previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants