The currect way to register sidebar in WordPress theme, create a custom sidebar in your theme, all things about sidebar and widgets.

How to Register Sidebar in WordPress

To register sidebar in WordPress, you need to register_sidebar() function and widgets_init action.

Register Sidebar

Copy the code and paste it in your “functions.php” file in your theme:

function wptime_register_sidebar(){
    register_sidebar( array(
        'name' => 'My Custom Sidebar', // your sidebar name
        'id' => 'my-sidebar-id', // your sidebar id, unique id (we need it later)
        'description' => 'A custom sidebar in my theme.', // your sidebar description
        'before_widget' => '<aside id="%1$s" class="widget %2$s">', // your widget wrap
        'after_widget' => '</aside>', // close widget wrap
        'before_title' => '<h3 class="widget-title">', // your widget title wrap
        'after_title' => '</h3>' // close title wrap
    ) );
}
add_action( 'widgets_init', 'wptime_register_sidebar' );

Now you will find your sidebar:

register sidebar in wordpress

Display Widgets in Your Custom Sidebar

To display the widgets in your custom sidebar, you need to is_active_sidebar() and dynamic_sidebar() function with sidebar ID. For example, create your sidebar file “sidebar.php” in your theme, and paste this code:

<?php

    if ( is_active_sidebar('my-sidebar-id') ) { // Check if have widget in your custom sidebar or not
        ?>
            <div id="sidebar">
                <?php
                    dynamic_sidebar('my-sidebar-id'); // Display widgets in the sidebar
                ?>
            </div>
        <?php
    }

?>

You can display your sidebar in anyplace and any file, for example in “footer.php” file or any custom file, not just “sidebar.php” file.

What is Before and After Widget and Title

This is HTML elements of your widget wrap and widget title wrap, for example:

wordpress before and after widget

Create a Custom Widget with Options

Learn and create a custom widgets with options, the best tutorial with full example.