Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#8734 closed enhancement (invalid)

Call Sidebars by Static Name, Not Dynamic Number

Reported by: dcole07 Owned by:
Milestone: Priority: high
Severity: normal Version:
Component: Themes Keywords: reporter-feedback dev-feedback
Focuses: Cc:


When sidebars are call or referred to, it should be done by the (static) name given, not by the (dynamic) number when they get registered. If WordPress is going to stick with numbers, it should be like posts, where a (static) number is assigned for the life of the install. The problem with the current way, of referring to a sidebar by a number they get registered by WordPress, is that this number can change with the addition/subtraction of sidebars. That means the admin has to move and edit the widgets.

The widget arranger, as well as anything else that calls or references to Sidebars should use a static name for each sidebar, instead of a dynamic number.

Change History (5)

comment:1 DD325 years ago

So.. Sounds like you should pass in the Static name and static ID when creating the sidebar, So as to select which one you want to show, as well as being able to refer to it in CSS, as well as solving the widget arranger problems..


add_action('init', 'theme_sidebars');
function theme_sidebars() {
					'name' => 'Left Posts sidebar',
					'id' => 'left-posts-sidebar',
					'before_widget' => '<div class="widget">',
					'after_widget' => '</div>'
					'name' => 'Left Home sidebar',
					'id' => 'left-home-sidebar',
					'before_widget' => '<div class="widget">',
					'after_widget' => '</div>'

the code to call those looks like:

	$is_blog = ( is_home() || is_single() || is_archive() || is_attachment() );
	$sidebar = $is_blog ? 'left-posts-sidebar' : 'left-home-sidebar';
	<div class="sidebar <?php echo $sidebar ?>" id="<?php echo $sidebar ?>">

comment:2 jacobsantos5 years ago

  • Keywords needs-patch added

comment:3 jacobsantos5 years ago

  • Keywords needs-patch removed

comment:4 DD325 years ago

  • Keywords reporter-feedback dev-feedback added

comment:5 DD325 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Set the ID on the sidebars, and call it by that instead.

Eg: dynamic_sidebar('sidebar-left');

Note: See TracTickets for help on using tickets.