bu-ist / responsive-framework

3 stars 0 forks source link

Add class to body tag for page slug #308

Open smtierneybu opened 1 year ago

smtierneybu commented 1 year ago

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 commented 1 year ago

@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

desrosj commented 1 year ago

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.