admin管理员组文章数量:1130349
I am registering 3 sidebars on widgets_init
register_sidebar(array(
'name' => esc_html__('Left Sidebar','creatus'),
'id' => 'left',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// right sidebar
register_sidebar(array(
'name' => esc_html__('Right Sidebar','creatus'),
'id' => 'right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// lateral header sidebar
register_sidebar(array(
'name' => esc_html__('Lateral header sidebar','creatus'),
'id' => 'lateral-header-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
When I activate the theme for the first time on a clean WP install 6 widgets get automatically added to lateral-header-sidebar
Am I registering them the wrong way or why are they added to this particular sidebar and not any other?
Any help is appreciated.
I am registering 3 sidebars on widgets_init
register_sidebar(array(
'name' => esc_html__('Left Sidebar','creatus'),
'id' => 'left',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// right sidebar
register_sidebar(array(
'name' => esc_html__('Right Sidebar','creatus'),
'id' => 'right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// lateral header sidebar
register_sidebar(array(
'name' => esc_html__('Lateral header sidebar','creatus'),
'id' => 'lateral-header-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
When I activate the theme for the first time on a clean WP install 6 widgets get automatically added to lateral-header-sidebar
http://prntscr/l9cx84
Am I registering them the wrong way or why are they added to this particular sidebar and not any other?
Any help is appreciated.
Share Improve this question asked Oct 23, 2018 at 9:32 BennBenn 1,0731 gold badge15 silver badges32 bronze badges 1 |1 Answer
Reset to default 1Widgets are stored in the wp_options table ( assuming the database prefix is wp_ ). You can retrieve the option, and remove the widgets manually:
// Get all the associated widgets
$sidebar_widgets = get_option ( 'sidebars_widgets' );
// Check this specific sidebar
if ( isset( $sidebar_widgets [ 'lateral-header-sidebar' ] ) ) {
unset ( $sidebar_widgets [ 'lateral-header-sidebar' ] );
// Update the option
update_option ( 'sidebars_widgets', $sidebar_widgets );
}
You can do this in your theme activation hook.
I am registering 3 sidebars on widgets_init
register_sidebar(array(
'name' => esc_html__('Left Sidebar','creatus'),
'id' => 'left',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// right sidebar
register_sidebar(array(
'name' => esc_html__('Right Sidebar','creatus'),
'id' => 'right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// lateral header sidebar
register_sidebar(array(
'name' => esc_html__('Lateral header sidebar','creatus'),
'id' => 'lateral-header-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
When I activate the theme for the first time on a clean WP install 6 widgets get automatically added to lateral-header-sidebar
Am I registering them the wrong way or why are they added to this particular sidebar and not any other?
Any help is appreciated.
I am registering 3 sidebars on widgets_init
register_sidebar(array(
'name' => esc_html__('Left Sidebar','creatus'),
'id' => 'left',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// right sidebar
register_sidebar(array(
'name' => esc_html__('Right Sidebar','creatus'),
'id' => 'right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
// lateral header sidebar
register_sidebar(array(
'name' => esc_html__('Lateral header sidebar','creatus'),
'id' => 'lateral-header-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget_title_holder"><h3 class="widget-title">',
'after_title' => '</h3></div>',
));
When I activate the theme for the first time on a clean WP install 6 widgets get automatically added to lateral-header-sidebar
http://prntscr/l9cx84
Am I registering them the wrong way or why are they added to this particular sidebar and not any other?
Any help is appreciated.
Share Improve this question asked Oct 23, 2018 at 9:32 BennBenn 1,0731 gold badge15 silver badges32 bronze badges 1-
Your registration code looks fine to me. How's the rest of your theme code? Are there any other widget related functions that might hook into
after_switch_themefor example? Something along these lines, stackoverflow/questions/11757461/… Or are there any plugins that might be the cause? – Antti Koskinen Commented Oct 25, 2018 at 10:52
1 Answer
Reset to default 1Widgets are stored in the wp_options table ( assuming the database prefix is wp_ ). You can retrieve the option, and remove the widgets manually:
// Get all the associated widgets
$sidebar_widgets = get_option ( 'sidebars_widgets' );
// Check this specific sidebar
if ( isset( $sidebar_widgets [ 'lateral-header-sidebar' ] ) ) {
unset ( $sidebar_widgets [ 'lateral-header-sidebar' ] );
// Update the option
update_option ( 'sidebars_widgets', $sidebar_widgets );
}
You can do this in your theme activation hook.
本文标签: How to avoid widgets added to sidebar on theme activation
版权声明:本文标题:How to avoid widgets added to sidebar on theme activation? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749230688a2336430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


after_switch_themefor example? Something along these lines, stackoverflow/questions/11757461/… Or are there any plugins that might be the cause? – Antti Koskinen Commented Oct 25, 2018 at 10:52