0

I'm developing my own WP theme. But i have a problem with widgets. So , when i drag and drop widget to sidebar area , it's settings don't appear. Appears only after refresh page. But at the other themes works correctly.

My codes :

Registering Widget areas :

  <?php
function themename_register_sidebars(){
    register_sidebar( 
        array(
            'name' => __('Main Sidebar', 'themename'),
            'id'   => 'main-sidebar', 
            'before_widget' => '<div id="%1$s" class = "%2$s ch_widget widget_s1"><div class="ch_widget_container">',
            'after_widget'  => '</div></div>',
            'before_title'  => '<span class="ch_widget_title">',
            'after_title'   => '</span>'
        )
    );
    register_sidebar( 
        array(
            'name' => __('Sticky Sidebar', 'themename'),
            'id'   => 'sticky-sidebar',
            'before_widget' => '<div id="%1$s" class = "%2$s ch_widget widget_s1 "><div class="ch_widget_container">',
            'after_widget'  => '</div></div>',
            'before_title'  => '<span class="ch_widget_title">',
            'after_title'   => '</span>'
        )
    );
    register_sidebar( 
        array(
            'name' => __(' Footer 1', 'themename'),
            'id'   => 'footer-1',
            'before_widget' => '<div id="%1$s" class = "%2$s widget_section wg1"><div class = "widget_container auto_widget">',
            'after_widget'  => '</div></div>',
            'before_title'  => '<span class="widget_title">',
            'after_title'   => '</span>'
        )
    );
    register_sidebar( 
        array(
            'name' => __('Footer 2', 'themename'),
            'id'   => 'footer-2',
            'before_widget' => '<div id="%1$s" class = "%2$s widget_section wg2"><div class = "widget_container auto_widget">',
            'after_widget'  => '</div></div>',
            'before_title'  => '<span class="widget_title">',
            'after_title'   => '</span>'
        )
    );





}
add_action('widgets_init','themename_register_sidebars');

?>

Example sidebar :

      <section class = 'sidebar_container'>
 <?php
    if(is_active_sidebar( 'main-sidebar' )): 
        dynamic_sidebar('main-sidebar');
     endif ;
  ?>  
  </section>
  • Could you please clarify - does "at the other themes works correctly" mean you can add the same widget without any issues? Or are you just adding other widgets when you're using a different theme? Also, have you checked your console to see if there are any JS errors? – WebElaine Aug 27 '18 at 13:32
  • So , at the wordpress's own themes (twentyseventeen and others) widget settings appear without page refresh. But in my theme , widget settings (textboxes,buttons etc.) disappear.. I checked , there aren't any errors. – jahangir_kazimli Aug 27 '18 at 13:40
  • Where are the div id="%1$s" class = "%2$s variables coming from? – WebElaine Aug 27 '18 at 13:58
  • 1
    The code you posted above (init with register_sidebars and is_active_sidebar) is correct. There seems to be something other in your theme which will break this. If you have custom JS enqueued I would start by disabling this and see if it works again. @WebElaine div id="%1$s" class = "%2$s this code comes from register_sidebar function and will create the right ID and class, take a look at the codex. – LWS-Mo Aug 27 '18 at 14:02

Your Answer

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

Browse other questions tagged or ask your own question.