Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#31525 closed enhancement (duplicate)

Request for filter hook for has_nav_menu()

Reported by: dougwollison's profile dougwollison Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2
Component: Menus Keywords:
Focuses: Cc:


I have a plugin that creates dummy copies of nav menu locations for the purpose of having separate menus assigned to the same location but in different languages.

The current hook adds callbacks to the after_setup_theme and wp_nav_menu_args filter hooks to achieve this, replacing the original location setup/requested with copies for each language registered by the plugin.

This largely works perfectly well on all my sites, but I've been informed of issues with it working in many stock themes. The issue has to do with the theme calling has_nav_menu() to check if a menu is registered to a particular location. However, since no actual menu is assigned to that location, but rather the pseudo version for a particular language, it returns false.

My proposal is to add a filter to has_nav_menu() so that plugins can filter the result. Something like this:

function has_nav_menu( $location ) {
    $registered_nav_menus = get_registered_nav_menus();

    $result = isset( $registered_nav_menus[ $location ] );
    if ( ! $result ) {
        $locations = get_nav_menu_locations();
        $result = ! empty( $locations[ $location ] );

    return apply_filters( 'has_nav_menu', $result, $location );

Either that or a filter on get_registered_nav_menus() or get_nav_menu_locations().

Change History (2)

#1 @akibjorklund
8 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Closing this ticket as a duplicate of #32630.

#2 @swissspidy
8 years ago

  • Milestone Awaiting Review deleted

Duplicate of #32630.

Note: See TracTickets for help on using tickets.