function register_sidebar($args = array() {}

Builds the definition for a single sidebar and returns the ID.
The $args parameter takes either a string or an array with ‘name’ and ‘id’ contained in either usage. It will be noted that the values will be applied to all sidebars, so if creating more than one, it will be advised to allow for WordPress to create the defaults for you.


  • string|array $args: Builds Sidebar based off of ‘name’ and ‘id’ values

Return values

returns:The sidebar id that was added.

Defined actions

  • register_sidebar
    do_action( 'register_sidebar', $sidebar );

Source code

function register_sidebar($args = array()) {

	global $wp_registered_sidebars;

	$i = count($wp_registered_sidebars) + 1;

	$defaults = array(

		'name' => sprintf(__('Sidebar %d'), $i ),

		'id' => "sidebar-$i",

		'description' => '',

		'class' => '',

		'before_widget' => '<li id="%1$s" class="widget %2$s">',

		'after_widget' => "</li>\n",

		'before_title' => '<h2 class="widgettitle">',

		'after_title' => "</h2>\n",


	$sidebar = wp_parse_args( $args, $defaults );

	$wp_registered_sidebars[$sidebar['id']] = $sidebar;


	do_action( 'register_sidebar', $sidebar );

	return $sidebar['id'];



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: