unregister_sidebar()WP 2.2.0

Removes a sidebar from the list.

No Hooks.

Return

null. Nothing.

Usage

unregister_sidebar( $sidebar_id );
$sidebar_id(string|int) (required)
The ID of the sidebar when it was registered.

Examples

0

#1 Cancel registered sidebars

If you add this code to functions.php, the sidebars registered for the TwentyTen theme will be cancelled:

add_action( 'widgets_init', 'remove_some_widgets', 11 );

function remove_some_widgets(){

	// Unregister some widget panels
	unregister_sidebar( 'first-footer-widget-area' );
	unregister_sidebar( 'second-footer-widget-area' );
	unregister_sidebar( 'third-footer-widget-area' );
	unregister_sidebar( 'fourth-footer-widget-area' );
}

In the example, we set priority 11 to the widgets_init hook because the child theme's functions.php connects before the main one. This means that if you leave the field empty, the priority will be 10 and the widgets will not be cancelled.

By changing the priority of our hook, we can make sure that it will be called after the functions.php file of the parent theme is loaded.

Notes

  • Global. Array. $wp_registered_sidebars Registered sidebars.

Changelog

Since 2.2.0 Introduced.

Code of unregister_sidebar() WP 6.0

function unregister_sidebar( $sidebar_id ) {
	global $wp_registered_sidebars;

	unset( $wp_registered_sidebars[ $sidebar_id ] );
}