Hi, I am developing my own WP framework and currently I am working on the options panel. Now, I want to add an option to create as many sidebars as the user wants. Now, this is my code:
// when the button is clicked..
function register_new_sidebars() {
register_sidebar( array(
'name' => __( 'Test the panel', 'gateway' ),
'id' => 'test-options-panel',
'description' => __( 'The Test widget area', 'gateway' ),
'before_widget' => '<li class="widget-container %2$s" id="%1$s">',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'register_new_sidebars' );
It doesn’t work. When I wrap it with var_dump it returns the ID of the sidebar, which actually says the function works but it just doesn’t add the sidebar (in the widgets page).
Thanks.
Sorry, tried to edit the first post
Someone? It’s really frustrating.
- Sold between 250 000 and 1 000 000 dollars
- Won a Competition
- Author was Featured
- Item was Featured
- Exclusive Author
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Europe
- Bought between 10 and 49 items
I believe you should run your register_sidebar every time on init;
add_action( 'init', 'the_widgets_init' );
function the_widgets_init() {
if ( !function_exists('register_sidebars') )
return;
register_sidebar( array( 'name' => __( 'Test the panel', 'gateway' ), 'id' => 'test-options-panel', 'description' => __( 'The Test widget area', 'gateway' ), 'before_widget' => '<li class="widget-container %2$s" id="%1$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) );
}
So in options panel save ids or other params that you need and then on init loop throw those params and register_sidebar
mixey said
I believe you should run your register_sidebar every time on init;add_action( 'init', 'the_widgets_init' ); function the_widgets_init() { if ( !function_exists('register_sidebars') ) return; register_sidebar( array( 'name' => __( 'Test the panel', 'gateway' ), 'id' => 'test-options-panel', 'description' => __( 'The Test widget area', 'gateway' ), 'before_widget' => '<li class="widget-container %2$s" id="%1$s">', 'after_widget' => '</li>', 'before_title' => '’, ‘after_title’ => ‘
’, ) ); } So in options panel save ids or other params that you need and then on init loop throw those params and register_sidebar
I figured it out like an hour ago, I just made an array every time the user submits and then used add_action with the widgets_init hook.
Thank you anyway! 
