Take the 2-minute tour ×

I see it is possible to use add_filter with the body_class function, but I'm needing to add one to the get_body_class function.

How can I add a filter to a function that is not included in the list of already available filter hooks?


share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The body_class() function simply calls the get_body_class() and creates a HTML class string from it.

function body_class( $class = '' ) {

So, the body_class filter applies to both functions.

share|improve this answer
Thanks for the reply. I saw that in /wp-includes/post-template.php, and this is working, but I'm confused as to why. I added add_filter('body_class', 'my_handler'); in the plugin I'm writing. When I called get_body_class in a page template, it correctly returned the filtered class string. Perhaps I'm not understanding filters correctly, but if body_class is calling get_body_class (and not the other way around), why is this filter, which is added to body_class() also applied to get_body_class()? Just curious. –  robertwbradford Dec 12 '11 at 18:02
add comment

Your Answer


