Im staring to develop a theme but i have a litle issue. I’m trying to add a sidebar to my theme with this code:

function theme_2_widgets_init() {
    register_sidebar( array(
    'name'          => __('Sidebar', 'theme_2'),
    'id'            => 'sidebar-1',
    'description'   => __('Add widgets here to appear in your sidebar.', 'theme_2' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h4 class="widget-title">',
    'after_title'   => '</h4>',
) );
add_action('widgets_init', 'theme_2_widgets_init');

The thing is, when i go to Appearence -> widgets, my sidebar is there but there is an incative sidebar thats says “this sidebar is no longer available and does not show anywhere on your site…”

is this normal to happen?

  • why used aside tag in before_widget parameter? – Md. Mrinal Haque Mar 27 '17 at 15:40
  • Did you change the name of your sidebar after adding widgets to it? – Industrial Themes Mar 27 '17 at 15:44
  • @IndustrialThemes i didnt change anything. I've simple added this code to the functions.php and going to Appearence->Widgets, there was the sidebar and than, below the widget lis there is the incative sidebar. – eskimopest Mar 27 '17 at 15:53
  • @MrinalHaque, why not? I was having problems with the sidebar so, i copy this from twentyfifteen theme if im not mistakem. i thought that it could be something with the way i was creating the sidebar but the result is the same. – eskimopest Mar 27 '17 at 15:59

Change 'id' => 'sidebar-1', as your own sidebar name. For example, new sidebar name is sidebar-2 than, our function will -

add_action( 'widgets_init', 'theme_slug_widgets_init' );

    function twentyfifteen_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Widget Area', 'twentyfifteen' ),
        'id'            => 'sidebar-2',
        'description'   => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
add_action( 'widgets_init', 'twentyfifteen_widgets_init' );


|improve this answer|||||
  • i dont believe this will do anything. I have the exact same code in another theme i made as an experiment and was having the same issue. I solved it but dont know what i did... argh... – eskimopest Mar 27 '17 at 16:18
  • Your first code worked with another theme, because that theme don't register a siderbar-1 widget area id. id must be different. – Md. Mrinal Haque Mar 27 '17 at 16:23
  • its funny. maybe im making a big mess out of this but i've copy the first theme into a new folder named theme_3. the id is the same as before 'sidebar-1' and everything is fine. when i go to widgets there is my sidebar and all of the default widgets: search, recent posts, recent comments, etc... im going to make some experiments like a clean install of wordpress and see what it does. – eskimopest Mar 27 '17 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.