I’m having some trouble with my widgets. I’ve registered widget areas correctly; as the widgets are showing up in the “Appearance” menu. However widgets aren’t showing up in the Customizr section of WP; getting this error:

There are no widget areas currently rendered in the preview. Navigate in the preview to a template that makes use of a widget area in order to access its widgets here.

I’ve tried the solutions mentioned here: Widgets not displaying in theme customizer and here Widgets Section not displaying in theme customizer but had no luck.

My code is:

register_sidebar(array(
            'name' => 'Sidebar Widgets',
            'id' => 'sidebar-widgets',
            'before_widget' => '<section class="widget">',
            'after_widget' => '</section>',
            'before_title' => '<h4>',
            'after_title' => '</h4>'
        ));

<?php if ( is_active_sidebar( 'sidebar-widgets' ) ) : ?>
        <?php dynamic_sidebar('sidebar-widgets'); ?>
        <?php endif; ?>

Running WordPress 4.4.2.

I’ve tried the following things:
1. Tried dynamic_sidebar in different templates (header, front-page, index).
2. Tried navigating to different pages as suggested, no luck
3. No console errors
4. Tried theme on a different WordPress installation, no luck
5. Tried another theme, widgets working

Any other code I can add to this question to help troubleshoot?

1 Answer
1

The customizer needs the sidebar to be “displayed” in order to detect its existence on the page. In your code you display the sidebar only if it is “active” which means that it has at least one widget in it, otherwise when no widgets are included it is not displayed and therefore the customizer can not detect it.

Don’t check for sidebar “activity”, the display_sidebar should output empty div or a like if no widgets exist in it so no real point in preventing its execution.

Leave a Reply

Your email address will not be published. Required fields are marked *