Languages: English • Español • 日本語 Português do Brasil • (Add your language)
Builds the definition for a single sidebar and returns the ID. Call on "widgets_init" action.
<?php register_sidebar( $args ); ?>
<?php $args = array( 'name' => __( 'Sidebar name', 'theme_text_domain' ), 'id' => 'unique-sidebar-id', // ID should be LOWERCASE ! ! ! 'description' => '', 'class' => '', 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); ?>
id
argument value, you will get E_USER_NOTICE
messages in debug mode, starting with version 4.2."sidebar"
will be prepended to the class value. For example, a class of "tal"
will result in a class value of "sidebar-tal"
. (default: empty).<li id="%1$s" class="widget %2$s">
) Note: uses sprintf for variable substitution</li>\n
).<h2 class="widgettitle">
).</h2>\n
).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.
This will create a sidebar named "Main Sidebar" with <h2> and </h2> before and after the title:
add_action( 'widgets_init', 'theme_slug_widgets_init' ); function theme_slug_widgets_init() { register_sidebar( array( 'name' => __( 'Main Sidebar', 'theme-slug' ), 'id' => 'sidebar-1', 'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ), 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', ) ); }
id
property now triggers E_USER_NOTICE
.description
propertyregister_sidebar() is located in wp-includes/widgets.php
.
Sidebars: is_active_sidebar(), is_dynamic_sidebar(), dynamic_sidebar(), register_sidebars(), register_sidebar(), unregister_sidebar(), wp_register_sidebar_widget(), wp_unregister_sidebar_widget(), wp_get_sidebars_widgets(), wp_set_sidebars_widgets()