Make WordPress Core

Opened 9 years ago

Closed 4 years ago

#34042 closed enhancement (maybelater)

Conditional widget areas in Customizer

Reported by: looimaster's profile Looimaster Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: Customize Keywords:
Focuses: Cc:

Description

I would like to show a widget area in Appearance > Widgets and in Appearance > Customize only when the user enables the component which requires it in Customizer. The code below (1) doesn't dynamically add the widget area in Appearance > Customize if I adjust another option. Furthermore, (2) it doesn't display this conditional sidebar in the live preview:

if ( get_theme_mod( 'enable_side_panel' ) ) {
	register_sidebar( array(
		'name'          => __( 'Some Widget Area', 'sometheme' ),
		'id'            => 'sidebar-1',
		'description'   => '',
		'class'         => '',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>'
	) );
}

Furthermore, it would be nice to show all widget areas in Customizer (like it is in Appearance > Customize) regardless if they are currently visible on the page or not.

Reasons:
1) I constantly wonder how many options am I missing if they are not shown all at once.
2) To make sure that I customized everything I have to open my 10 subpages on the website which takes a lot of time and review what Customizer options have appeared on each page.
3) I'm never able to compare for example "Shop sidebar" from WooCommerce, "Page sidebar" and "Footer sidebar" to see if I reuse any widgets.
4) If I'm on static homepage which doesn't have sidebar then it's rather obvious to me that "Blog sidebar" is not there and I know where is it and requiring me to click on the "Blog" link to customize that sidebar is one step too many.

Maybe in some themes and plugins it's a good idea to show widget areas conditionally but in most it would be better to show all available options at all times.

Change History (2)

#1 @westonruter
9 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.3.1 to 3.9

Hi Looimaster

I would like to show a widget area in Appearance > Widgets and in Appearance > Customize only when the user enables the component which requires it in Customizer.

Yes, this would be a problem as you are doing it. Sidebars can't currently be dynamically added to the Customizer without adding some non-trivial code to support that; it's not in core currently. An alternative approach is you could always register the sidebar, but just not call dynamic_sidebar() on it if the theme-mod is not enabled. This would allow the sidebar to appear it gets rendered in the preview.

Furthermore, it would be nice to show all widget areas in Customizer (like it is in Appearance > Customize) regardless if they are currently visible on the page or not.

The Customizer is a framework for live preview, so it doesn't make sense to show a sidebar when it isn't rendered in the preview. If those widget areas are to be modified en mass, they can be done so on the widgets admin page.

4) If I'm on static homepage which doesn't have sidebar then it's rather obvious to me that "Blog sidebar" is not there and I know where is it and requiring me to click on the "Blog" link to customize that sidebar is one step too many. Maybe in some themes and plugins it's a good idea to show widget areas conditionally but in most it would be better to show all available options at all times.

Please see #33052 and the proposed notice that is displayed.

#2 @celloexpressions
4 years ago

  • Resolution set to maybelater
  • Status changed from new to closed

Closing for now based on lack of movement/interest. Plugins are free to experiment with implementing (or removing) conditional visibility for widget areas and widgets. This can be reconsidered for core if there is more support for making a change.

Note: See TracTickets for help on using tickets.