It maybe that the filter is firing too late for this to work, but this is what I have, and it isn’t working.
class someClass()
{
public function __construct()
{
add_filter( 'body_class', array( 'someClass', 'body_class_filter') );
}
public function body_class_filter( $classes )
{
$classes[] = 'some-class';
return $classes;
}
}
I have also tried
add_filter( 'body_class', array( $this, 'body_class_filter') );
or
add_filter( 'body_class', array( &$this, 'body_class_filter') );
and
add_filter( 'body_class', array( __CLASS__, 'body_class_filter') );
But that filter does not appear to be firing. I’ve even put in a trigger_warning() in the function body_class_filter() to see if the code is even processing and it doesn’t appear to be since no warning is showing up in the debug.log.
Ideas?
Are you instantiating the class? Add
new someClass();
at the bottom of your file. My suggestion would be to go with the following version ofadd_filter()
:Finally, if you are instantiating the class, are you doing so before the
body_class
filter is run?