body_class array to string causing error
-
If I add body_class filter to my theme, few other plugins cause error as follows.
Fatal error: Uncaught Error: [] operator not supported for strings
My code:
function BodyClass(array $classes){ $classes[] = 'scroller'; error_log(gettype($classes)); return $classes; } apply_filters( 'body_class', 'BodyClass');
I reviewed the plugin code, the code use similar to my code above, to add their classes. But the other plugin code receive
$classes
as string instead of array.– If I disable my filter, they work correctly.
– any error_log is not logging anything, so assuming its not called at all before the error is raised.Any guidance is appreciated.
Below is call stack.
Call stack: qi_addons_for_elementor_add_mobile_class() wp-includes/class-wp-hook.php:303 WP_Hook::apply_filters() wp-includes/plugin.php:189 apply_filters() wp-content/themes/sanp22/inc/theme-support.php:525 require() wp-content/themes/sanp22/functions.php:15 include() wp-settings.php:546
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘body_class array to string causing error’ is closed to new replies.