how would I go about creating a filter for the
body_class() tag that allows me to add the the parent pages slug name as a class to the body whenever visiting a subpage or post?
You'll get two additional classes:
I tried looking in wordpresses post-template.php file where the body class is located and found the function that generates the class I want to be added when Im also on subpages or posts and copied it into my functions.php...then I added the
This is what I tried:
This is what's outputed:
Notice page-template-, thats the class I need but with the rest of the template name...so it would be page-template-NAME-php.
My goal is to basically always have the parent template name class present in the body tag when visiting ANY page, ie. Pages, Subpages, Posts, etc...
So I managed to get t31os's code working even though Im not sure I even did it right?
I placed his filter in my functions.php first:
Then I added my last bit of code that I barrowed from wordpresses core
You'll also notice I didnt want it to read - page-template-name.php so I added the
This is one step closer, but unfortunately it still doesn't retrieve the parent template name in that way when visiting single posts or subpages, it only grabs the current template in use. This is also not very useful on single post pages since it renders:
Any additional help is super appreciated!!! -- Its almost working!!!