How to register_widget that has functioned like a sidebar for WordPress

I want to register_widget that has functioned like a sidebar, can drag many widget. I see it before, used with one plugin but I forgot it. Please see the screenshot for reference.

enter image description here

Related posts

Leave a Reply

1 comment

  1. (1) If you want to create a widget area, do this:

    Add the following code to the functions file, making sure you place it in between php tags:

    if ( function_exists('register_sidebar') ){
        register_sidebar(array(
            'name' => 'my_new_widget',
            'before_widget' => '<div id="my-new-sidebar-widget">',
            'after_widget' => '</div>',
            'before_title' => '',
            'after_title' => '',
    ));
    }
    

    Give the widget area a name – e.g. my_new_widget and in the before/after options you can place code which you wish to appear wrapped around either the widget itself or the title.

    Then go to the area in your them where you want the widget to be displayed (in your header.php, index.php, single.php, etc.), and do this:

    In your WordPress themes editor open the header.php file.

    Find the location where you want to place the menu and add the following code to the header.php file:

    <?php /* Widgetized sidebar */
        if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('my_new_widget') ) 
    

    Then when you go to your dashboard, you will see a new widget area in Appearances >> Widgets.

    Here’s another way to create a new widget area.


    (2) If you’re talking about creating a new sidebar:

    You’ll want to begin by finding any existing “register_sidebar” entries in your functions.php file. Some of mine have the following existing sidebar definition for the single default sidebar:

    if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h2>',
    ));
    }
    

    To register your second sidebar, we simply add the following code to the functions.php file:

    if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
    'name' => 'Homepage Sidebar',
    'id' => 'homepage-sidebar',
    'description' => 'Appears as the sidebar on the custom homepage',
    'before_widget' => '<div style="height: 280px"></div><li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h2>',
    ));
    }
    

    So basically, you just:

    • Told your WordPress installation, “we are adding a second sidebar area that we’ll use in our theme”
    • The sidebar’s name is “Homepage Sidebar”
    • The ID of the sidebar (we’ll refer to that ID later) is “homepage-sidebar”; you can choose “footer-sidebar”, “second-sidebar” or anything you want
    • You added the description “Appears as the sidebar on the custom homepage” that will display just under the sidebar’s title.

    If you upload your new functions.php file to your WordPress installation, you should see your new sidebar if you browse from your WordPress dashboard to Appearance, then Widgets.