For our customization want to create a new widget in WordPress programmatically then place the following snippet in functions.php within your theme folder!.

add_action( 'widgets_init', 'create_new_widget' );
function create_new_widget() 
{
    register_sidebar( array(
        'name' => __( 'Custom Sidebar', 'theme-slug' ),
        'id' => 'custom_sidebar',
        'description' => __( 'Your widget description here', 'theme-slug' ),       
    ) );
}

After that you can call this sidebar by following code. Wherever you want add the following code in that particular place.

dynamic_sidebar( 'left-sidebar' );

Have any doubt, then comment here!

1 Comment on Create widget in WordPress programmatically

Leave a Reply

Your email address will not be published. Required fields are marked *