GuiguiSensei
GuiguiSensei

Reputation: 11

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

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

Upvotes: 1

Views: 1054

Answers (1)

Hossein
Hossein

Reputation: 3107

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

Upvotes: 1

Related Questions