unregister_nav_menu() WordPress Function

The unregister_nav_menu() function is used to remove a registered navigation menu from a WordPress site. This function can be useful if you want to remove a menu that is no longer needed or if you want to replace an existing menu with a new one.

unregister_nav_menu( string $location ) #

Unregisters a navigation menu location for a theme.


Parameters

$location

(string)(Required)The menu location identifier.


Top ↑

Return

(bool) True on success, false on failure.


Top ↑

More Information

Usage:
unregister_nav_menu( 'primary' );

Top ↑

Source

File: wp-includes/nav-menu.php

function unregister_nav_menu( $location ) {
	global $_wp_registered_nav_menus;

	if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[ $location ] ) ) {
		unset( $_wp_registered_nav_menus[ $location ] );
		if ( empty( $_wp_registered_nav_menus ) ) {
			_remove_theme_support( 'menus' );
		}
		return true;
	}
	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.