Skip to content
wp-skills
Register
tools/sidebar-generator

WordPress Sidebar Generator

WordPress Sidebar Generator is a tool that allows WordPress users to easily create customizable sidebars.

Not register_sidebar: naming the callback after the core function it calls is a fatal redeclaration.

Your theme or plugin's own domain, for the name and description below.

Sidebars1
  • #1

    The heading Appearance → Widgets files this area under.

    What dynamic_sidebar( '…' ) takes in your template. Lower case and hyphens.

    Sits under the name on the widgets screen. Optional, and worth writing when a theme has several areas.

    %1$s is the widget's id and %2$s its class names — WordPress fills both in.

    Has to close whatever Before widget opened, or the markup nests wrongly.

    Wraps the widget's own title. A heading level is what most themes want here.

    Wraps the whole area. %1$s is the id above and %2$s the class below — this is the only place either reaches the page.

    Only reaches the page through Before sidebar's %2$s. Leave that blank and this does nothing at all.

    What lets the block editor's widget screen manage this area. Off is core's default.

snippet.php
// Register custom sidebars
function wpskills_custom_sidebars() {
	register_sidebar(
		array(
			'name'           => __( 'My Sidebar', 'text-domain' ),
			'description'    => __( 'My Sidebar Description', 'text-domain' ),
			'id'             => 'sidebar-id',
			'class'          => 'my-sidebar',
			'before_widget'  => '<li id="%1$s" class="widget %2$s">',
			'after_widget'   => '</li>',
			'before_title'   => '<h2 class="widgettitle">',
			'after_title'    => '</h2>',
			'before_sidebar' => '<aside id="%1$s" class="widget-area %2$s">',
			'after_sidebar'  => '</aside>',
			'show_in_rest'   => false,
		)
	);
}
add_action( 'widgets_init', 'wpskills_custom_sidebars' );