WordPress theme creation : There are no widget areas on the page shown

For Registering Widget In WordPress:

Add this code Into your theme functions.php file.

add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Main Sidebar', 'theme-slug' ),
        'id' => 'sidebar-1',
        'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
        'before_widget' => '',
    'after_widget'  => '',
    'before_title'  => '',
    'after_title'   => '',
    ) );
}

Instead of theme_slug_ you should use your own theme slug. Also you can check this page for more information.

After Registering Widget Write in Any Custom Template Or where you want to display that Widget:

<?php get_sidebar('Main Sidebar'); ?>
https://codex.wordpress.org/Function_Reference/register_sidebar

Leave a Comment