I am using the Theme Customizer to let users customize how their website looks.
I noticed on the Twenty Fifteen theme there is a panel for Widgets. I have seen this on quite a few other themes too, and the code for the panel has not been added to customizer.php
(as far as I can tell)
On my theme, I have a few sidebars on the homepage. You can customize the widgets through Appearance > Widgets
menus, however the Widgets panel in the customizer is not displaying.
How can I get it to show in the customizer so the user does not have to keep switching out to change the widgets?
My code for registering the sidebar:
function widgets_init_mysite() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'mytheme' ),
'id' => 'sidebar-1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'widgets_init_mysite' );
I add the sidebar to the page using dynamic_sidebar( 'sidebar-1' )
It is definitely displayed because I added widgets through Appearance > Widgets
and I can see them in the customizer.
Note: One interesting thing I did find. I registered 5 Sidebars, with IDs of sidebar-1
, sidebar-2
etc. In Firefix, I went to the theme customizer and Inspect Element. I found the Widgets panel existed, but had display: none
. What is more interesting, in the ul
sub-navigation, there were 5 li
elements with the class section-sidebar-widgets-sidebar-1
(the last number changed for all the sidebars).
I checked the other sections I had made, and the class always started with section-
, and then the section ID. I tried changing the panel of the sidebars to my panel like so:
$wp_customize->get_section( 'sidebar-widgets-sidebar-1' )->panel = 'my-panel';
But nothing happened. This is weird because I know pretty much definitely know the names of the Sidebar Sections, but changing their panel does nothing...
customizer.php
file, and I am not comfortable doing that. I just want to know if there is some Wordpress feature that lets you enable that panel, not for my code to be debugged.customizer.php
and the panel still did not show.