I am using a theme_mod string from customizer to generate custom sidebar, but it is called from another function. This is my code:
function call_sidebar_function() {
if ( get_theme_mod( 'enable_sidebar' ) ) {
$name = "mySidebarName";
$numberOfSidebars = get_theme_mod('number_of_sidebars');
generate_sidebars($name, $numberOfSidebars);
}
}
function generate_sidebars($name, $numberOfSidebars) {
$i = 1;
foreach ($numberOfSidebars as $sidebar) {
register_sidebar(
array(
'name' => $name.$i,
'id' => $name.$i,
)
);
$i++;
}
}
add_action( 'widgets_init', 'generate_sidebars' );
widget_init
in your posted code. So it's pretty hard to say, what is wrong exactly...