Codex

Function Reference/register sidebar

Contents

Description

Builds the definition for a single sidebar and returns the ID.

Usage

 <?php register_sidebar$args ); ?> 

Default Usage

 <?php $args = array(
    
'name'          => sprintf(__('Sidebar %d'), $i ),
    
'id'            => 'sidebar-$i',
    
'before_widget' => '<li id=\"%1$s\" class=\"widget %2$s\">',
    
'after_widget'  => '</li>',
    
'before_title'  => '<h2 class=\"widgettitle\">',
    
'after_title'   => '</h2>' ); ?> 

Parameters

$args
(string/array) (optional) Builds Sidebar based off of 'name' and 'id' values.
Default: None
  • name - Sidebar name.
  • id - Sidebar id.
  • before_widget - Text to place before every widget.
  • after_widget - Text to place after every widget.
  • before_title - Text to place before every title.
  • after_title - Text to place after every title.

The optional $args parameter is an associative array that will be passed as a first argument to every active widget callback. (If a string is passed instead of an array, it will be passed through parse_str() to generate an associative array.) The basic use for these arguments is to pass theme-specific HTML tags to wrap the widget and its title.

Notes

  • The only times you might need to call this function instead of register_sidebars() are when you want to give unique names to sidebars, such as “Right Sidebar” and “Left Sidebar”, or when they should be marked up differently. The names only appear in the admin interface but they are also used as an index for saving the sidebar arrangements. Consequently, sidebars can have their arrangements reused and overwritten when another theme is chosen that uses the same names.
  • The default before/after values are intended for themes that generate a sidebar marked up as a list with h2 titles. This is the convention we recommend for all themes and any theme built in this way can simply register sidebars without worrying about the before/after tags. If, for some compelling reason, a theme cannot be marked up in this way, these tags must be specified when registering sidebars. It is recommended to copy the id and class attributes verbatim so that an internal sprintf call can work and CSS styles can be applied to individual widgets.

Example

This will create a sidebars named "RightSideBar" with <h1> and </h1> before and after the title:

register_sidebar( array('name'=>'RightSideBar', 'before_title'=>'<h1>','after_title'=>'</h1>') );

Change Log

Since: 2.2.0

Source File

register_sidebar() is located in wp-includes/widgets.php.

Related

Widgets API: is_active_sidebar, register_sidebars, register_sidebar, unregister_sidebar, is_dynamic_sidebar, dynamic_sidebar, register_sidebar_widget, unregister_sidebar_widget, wp_register_sidebar_widget, wp_unregister_sidebar_widget, wp_get_sidebars_widgets, wp_set_sidebars_widgets, is_active_widget, the_widget, register_widget, unregister_widget, register_widget_control, unregister_widget_control, wp_register_widget_control, wp_unregister_widget_control, wp_convert_widget_settings, wp_get_widget_defaults, wp_widget_description

See also index of Function Reference and index of Template Tags.