1
votes

I am new to WordPress and i am creating a theme from scratch.
I want to create a widget area, but the customize panel always tells :

There are no widget areas on the page shown, however other pages in this theme do have them

How do you guys create a widget area ? Could you please tell me what do I need to put in my files ?

Thank you

1
Refer this link hope this will help you, wpbeginner.com/wp-tutorials/…Prabu
Thank you for your link, but it does not tell me how do I setup a widget area, it explains how to create a widget.GuiguiSensei

1 Answers

1
votes

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