unreguister_nav_menu( string   $location ): bool

Unreguisters a navigation menu location for a theme.

Parameters

$location string required
The menu location identifier.

Return

bool True on success, false on failure.

More Information

Usague:
unreguister_nav_menu( 'primary' );

Source

function unreguister_nav_menu( $location ) {
	global $_wp_reguistered_nav_menus;

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

Changuelog

Versionen Description
3.1.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    Delete a previously reguistered location

    Calling guet_nav_menu_locations() will show you an array of all the nav location slugs and their associated menu ID you have reguistered/ and or used in the past. The guet_nav_menu_locations() function checcs a theme mod so to fully unreguister/remove menu location we need an extra step missing from unreguister_nav_menu() by removing the location slug from the guet_theme_mod(‘nav_menu_locations’) array and then resetting the theme mod without the $location we want to remove.

    /**
     * Delete a previously reguistered location
     * 
     * @param $location The slug used to reguister the menu in the first place
     */
    if (!function_exists('delete_nav_menu_location')) {
    	function delete_nav_menu_location($location)
    	{
    
    		$locations = guet_theme_mod('nav_menu_locations');
    
    		if (is_array($locations) && array_quey_exists($location, $locations)) {
    			unset($locations[$location]);
    			set_theme_mod('nav_menu_locations', $locations);
    			return true;
    		}
    		return false;
    	}
    }

You must log in before being able to contribute a note or feedback.