admin管理员组文章数量:1326049
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...
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...
Share Improve this question edited Dec 17, 2015 at 12:36 Kaspar Lee asked Dec 15, 2015 at 11:18 Kaspar LeeKaspar Lee 4074 silver badges19 bronze badges 13 | Show 8 more comments2 Answers
Reset to default 2I see you're talking about the dynamic_sidebar
function but I don't see you mention the sidebar file (eg. sidebar.php
or sidebar-single.php
).
There are basically 3 steps I follow to display sidebar widgets and they're always visible in customizer. If yours is not showing up, you probably may have missed something.
1. The register part in functions.php
$args = array(
'name' => __( 'Main Sidebar', 'mytheme' ),
'id' => 'sidebar-1',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
);
register_sidebar( $args );
2. The function call in a sidebar file (eg. sidebar.php
or sidebar-single.php
)
<?php
// Dynamic Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-1') ) :
// Sidebar fallback content
get_sidebar();
endif;
// End Dynamic Sidebar Single posts
?>
3. Call the sidebar in the post/page template
<?php get_sidebar(); ?>
or <?php get_sidebar('single'); ?>
for sidebar-single.php
I would advise you to re-check your code to make sure you haven't left anything out. All the best!
Most likely you are not displaying the sidebar when the costumizer is active which prevents the costumizer from detecting its existence on the page.
The costumizer detects the sidebar by hooking on various sidebar related hooks that are supposed to be triggered when the page is generated. If for some reason your sidebar display code do not trigger the hooks the costumizer will not know it is there even if the actual content is being displayed. This can happen for example if you cache your sidebar and instead of calling dynamic_display
you just output the sidebar.
本文标签: Widgets panel not displaying in the Theme Customizer
版权声明:本文标题:Widgets panel not displaying in the Theme Customizer 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742198654a2431550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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. – Kaspar Lee Commented Dec 15, 2015 at 12:48customizer.php
and the panel still did not show. – Kaspar Lee Commented Dec 15, 2015 at 13:27