753 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
+4 more
AdamGold says

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.

753 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
+4 more
AdamGold says

Sorry, tried to edit the first post

753 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
+4 more
AdamGold says

Someone? It’s really frustrating.

833 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Won a competition
  • Made it to the Authors' Hall of Fame
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
+8 more
wpbakery says

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

753 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
+4 more
AdamGold says

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! :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by