unregister_nav_menu()
Unregisters a navigation menu location for a theme.
No Hooks.
Return
true|false
. True on success, false on failure.
Usage
unregister_nav_menu( $location );
- $location(string) (required)
- The menu location identifier.
Examples
#1 Basic example
How to delete a previously registered navigation menu with identifier primary
. Do it on later hook init after all registrations:
add_action( 'init', 'theme_register_nav_menu', 20 ); function theme_register_nav_menu() { unregister_nav_menu( 'primary' ); }
Notes
- Global. Array. $_wp_registered_nav_menus
Changelog
Since 3.1.0 | Introduced. |
unregister_nav_menu() unregister nav menu code WP 6.6.1
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; }