2

I'm encountering a strange issue with WordPress. I'm building a theme and the theme customization is driven by Customizer.

So, basically in functions.php I'm adding

add_theme_support( 'widget-customizer' );

i'm registering a sidebar with:

register_sidebar( array(
   'name' => __( 'Test Sidebar' ),
   'id' => 'test-sidebar',
));

then in index.php i'm adding the common get_footer(); and in footer.php I have:

<?php if ( is_active_sidebar( 'test-sidebar' ) ): ?>
    <div id="test-sidebar" class="sidebar">
        <?php dynamic_sidebar( 'test-sidebar' ); ?>
    </div>
<?php endif; ?>

Now the first strange issue is that in the preview window I can see any widget added via admin page in Appearance but in the customizer widget section I can't see any area and I get this message

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.

But the second strange issue is that if in my functions.php I add:

   add_action( 'wp_footer', function () {
       ?>
       <?php if ( is_active_sidebar( 'test-sidebar' ) ): ?>
            <div id="test-sidebar" class="sidebar">
            <?php dynamic_sidebar( 'test-sidebar' ); ?>
        </div>
        <?php endif; ?>
        <?php
    } );

Now I can see the widget area in customizer.

What could be the problem?

  • This is how the good question should look like. – prosti Dec 3 '16 at 1:14
  • Thanks @prosti. Furthermore it's still not a very good question because the question isn't direct and it not point to an argument like stack community want. But I'm struggling with this problem. – koMah Dec 3 '16 at 1:29
  • @koMah I'm not sure if widget-customizer is a valid argument for add_theme_support(). Do you have any additional plugins installed? – Sven Dec 3 '16 at 2:18
  • No @Sven, clean Wordpress install, without plugins. – koMah Dec 3 '16 at 2:26
  • @koMah, actually your question was sufficient for the good answer. – prosti Dec 6 '16 at 21:39
0

After a entire night I've get the answer. Reflecting on why the customizer showing me the widget areas only through the wp_footer hook I have checked my footer.php and the problem was that wp_footer() were called before the sidebar section.

   /* Always have wp_footer() just before the closing </body>
    * tag of your theme, or you will break many plugins, which
    * generally use this hook to reference JavaScript files.
    */
    wp_footer();

Moving it after sidebars all works perfectly.

  • 1
    That's right. The wp_footer action must fire in the preview so that customize-preview.js will be printed along with all of the other supporting data and scripts for the customizer preview to interface with the customizer controls pane. – Weston Ruter Dec 3 '16 at 15:09
  • Hey @WestonRuter, i know you!! You're a great with customizer. Did you know how dynamic Menu Locations can be refreshed in customizer? I have opened a ticket here – koMah Dec 3 '16 at 17:36
  • hey, dynamic menu locations are not supported currently. You'll need to register then unconditionally. However, you can hide the controls for them via adding an active_callback for their controls in the customizer. – Weston Ruter Dec 4 '16 at 5:56
0

Yes, wp_footer() hook is important. If you remove wp_footer hook from the footer.php file you will get the message from class-wp-customize-widgets.php.

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.

If you remove the wp_footer hook the whole customizer section will be there, but it will not work as @WestonRuter pointed, because of customize-preview.js will not be there.


I would just provide few tips:

You don't need to add add_theme_support( 'widget-customizer' ); widget-customizer plugin is an integral part of WordPress core now, and you have that support ready.

The other thing, footer.php is probably not the smartest place to put your sidebar organization-wise. You may check the twentysixteen WordPress theme, to see the organization.

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.