register_sidebars()
Creates multiple sidebars.
If you wanted to quickly create multiple sidebars for a theme or internally. This function will allow you to do so. If you don't pass the 'name' and/or 'id' in $args, then they will be built for you.
No Hooks.
Return
null
. Nothing (null).
Usage
register_sidebars( $number, $args );
- $number(int)
- Number of sidebars to create.
Default: 1 - $args(array|string)
Array or string of arguments for building a sidebar.
Default: array()
-
id(string)
The base string of the unique identifier for each sidebar. If provided, and multiple sidebars are being defined, the ID will have "-2" appended, and so on. followed by the number the sidebar creation is currently at.
Default: 'sidebar-' - name(string)
The name or title for the sidebars displayed in the admin dashboard. If registering more than one sidebar, include '%d' in the string as a placeholder for the uniquely assigned number for each sidebar. for the first sidebar, otherwise 'Sidebar %d'.
Default: 'Sidebar'
-
Examples
#1 Single panel registration
Analogue of register_sidebar():
register_sidebars( 1, [ 'name' => 'Sidebar on home page', 'id' => 'homepage-sidebar', 'description' => 'Displayed as a sidebar only on the home page of the site.', 'before_widget' => '<li id="%1$s" class="homepage-widget-block %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', ] );
id
parameter value must be in lowercase and no spaces!
#2 Registration of two panels
This example shows how to register 2 panels named "Foobar 1", "Foobar 2", "Foobar 3":
register_sidebars( 3, [ 'name' => 'Foobar %d', 'id' => 'right-sidebar', 'description' => 'These widgets will be shown in the right column of the site', 'before_title' => '<h2>', 'after_title' => '</h2>' ] );
id
parameter will changed automatically, the suffix will be added: right-sidebar
, right-sidebar-2
, right-sidebar-3
#3 Create 2 panels and put the title of each widget in the <h1>
tag:
register_sidebars( 2, [ 'before_title' => '<h1>', 'after_title' => '</h1>', ] );
The same, only we specify the parameters as a string:
register_sidebars( 2, "before_title=<h1>&after_title=</h1>" )
Notes
- See: register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
- Global. Array. $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
Changelog
Since 2.2.0 | Introduced. |