The register_sidebar() WordPress PHP function builds the definition for a single sidebar and returns its ID.
Usage
register_sidebar( $args );
Parameters
$args
(array|string, Optional): Array or string of arguments for the sidebar being registered. See the details below:name
(string): The name or title of the sidebar displayed in the Widgets interface. Default is ‘Sidebar $instance’.id
(string): The unique identifier by which the sidebar will be called. Default is ‘sidebar-$instance’.description
(string): Description of the sidebar, displayed in the Widgets interface. Default is an empty string.class
(string): Extra CSS class to assign to the sidebar in the Widgets interface.before_widget
(string): HTML content to prepend to each widget’s HTML output when assigned to this sidebar. Default is an opening list item element.after_widget
(string): HTML content to append to each widget’s HTML output when assigned to this sidebar. Default is a closing list item element.before_title
(string): HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element.after_title
(string): HTML content to append to the sidebar title when displayed. Default is a closing h2 element.before_sidebar
(string): HTML content to prepend to the sidebar when displayed. Default is an empty string.after_sidebar
(string): HTML content to append to the sidebar when displayed. Default is an empty string.show_in_rest
(bool): Whether to show this sidebar publicly in the REST API. Defaults to only showing the sidebar to administrator users.
More information
See WordPress Developer Resources: register_sidebar()
Examples
Register a basic sidebar
Registers a simple sidebar with default settings.
register_sidebar();
Register a sidebar with a custom name and description
Registers a sidebar with a custom name and description for the Widgets interface.
register_sidebar( array( 'name' => 'Custom Sidebar', 'description' => 'A custom sidebar for my theme.', ));
Register a sidebar with custom HTML structure
Registers a sidebar with custom HTML structure for widgets and titles.
register_sidebar( array( 'name' => 'Custom HTML Sidebar', 'before_widget' => '<div class="widget-container">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ));
Register multiple sidebars
Registers multiple sidebars using a loop.
for ( $i = 1; $i <= 3; $i++ ) { register_sidebar( array( 'name' => "Footer Sidebar $i", 'id' => "footer-sidebar-$i", )); }
Register a sidebar visible to administrator users in REST API
Registers a sidebar that is publicly visible to administrator users in the REST API.
register_sidebar( array( 'name' => 'REST API Sidebar', 'show_in_rest' => true, ));