I don’t think that there is a much smarter way to write this code in a procedural style, so basically your code looks okay.
But there’s a logic error in your body_class_before_header()
function which might cause the issue: If the conditional block is not executed, the function will return NULL
but as it is a callback on a filter it should always return at least the unfiltered parameter value:
// add body class if before-header-widget is active
add_filter( 'body_class', 'body_class_before_header' );
function body_class_before_header( $classes ) {
if ( is_active_sidebar( 'before-header-widget-area' ) ) {
$classes[] = 'before-header';
//don't return here (only)
}
//return $classes anyway
return $classes;
}
There’s one more small syntax improvement, maybe.
function body_class_layouts( $classes ) {
// add body class if both sidebars are active
if ( is_active_sidebar( 'sidebar-right' ) && is_active_sidebar( 'sidebar-left' ) ) {
$classes[] = 'sidebar-content-sidebar';
}
// add body class for if right sidebar is active
elseif ( is_active_sidebar( 'sidebar-right' ) ) {
$classes[] = 'content-sidebar';
}
// add body class for if left sidebar is active
elseif ( is_active_sidebar( 'sidebar-left' ) ) {
$classes[] = 'sidebar-content';
}
// add body class if no sidebars are active
else {
$classes[] = 'full-width-content';
}
return $classes;
}
I removed all the return
statements from the conditional blocks and moved it to the end of the function. This might help to avoid a NULL
return under certain conditions.