Closed georgegrigorita closed 9 years ago
Do you have another array using the variable $choices?
Yes, there are 2 more (left from the customizer-library examples). I've commented their code but I get the same results.
Instead of commenting out the code, try first to give your variable a distinct name (like $sidebar_choices). If that still doesn't work, I wonder if it'll work with a dropdown/select instead of radio:
$sidebar_choices = array(
'sidebar-right' => 'Right Sidebar',
'sidebar-left' => 'Left Sidebar',
'no-sidebar' => 'No Sidebar'
);
$options['layout-section'] = array(
'id' => 'layout-section',
'label' => __( 'Layout', 'sylph' ),
'section' => $section,
'type' => 'select',
'choices' => $sidebar_choices,
'default' => 'sidebar-right',
);`
I tried both cases (different variable, different type), but I'm still getting the same body-class (no-sidebar) instead of the default one (sidebar-right).
It looks like you're using "layout-section" as the theme mod (not "layout", that is the name of the section in your example).
To debug something like this, first make sure that the theme mod is getting set appropriately:
echo get_theme_mod( 'layout-section', customizer_library_get_default( 'layout-section' ) );
Code should look something like this:
function test_body_classes( $classes ) {
$classes[] = get_theme_mod( 'layout-section', customizer_library_get_default( 'layout-section' ) );
return $classes;
}
add_filter( 'body_class', 'test_body_classes' );
I'm trying to add a body class via the Layout section (
type: radio
) in my customizer. I think I'm missing something because thebody-class
is alwaysno-sidebar
, which is not correct. It's like theget_theme_mod
can't access the$choices
array... Any help with this will be much appreciated.In
customizer-options
:In
functions
: