Title: WP_Navigation_Fallback::get_fallback
Published: August 8, 2023
Last modified: August 20, 2026

---

# WP_Navigation_Fallback::get_fallback(): 󠀁[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)󠁿|null

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#wp--skip-link--target)

Gets (and/or creates) an appropriate fallback Navigation Menu.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#return)󠁿

 [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|null the 
fallback Navigation Post or null.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#source)󠁿

    ```php
    public static function get_fallback() {
    	/**
    	 * Filters whether or not a fallback should be created.
    	 *
    	 * @since 6.3.0
    	 *
    	 * @param bool $create Whether to create a fallback navigation menu. Default true.
    	 */
    	$should_create_fallback = apply_filters( 'wp_navigation_should_create_fallback', true );

    	$fallback = static::get_most_recently_published_navigation();

    	if ( $fallback || ! $should_create_fallback ) {
    		return $fallback;
    	}

    	$fallback = static::create_classic_menu_fallback();

    	if ( $fallback && ! is_wp_error( $fallback ) ) {
    		// Return the newly created fallback post object which will now be the most recently created navigation menu.
    		return $fallback instanceof WP_Post ? $fallback : static::get_most_recently_published_navigation();
    	}

    	$fallback = static::create_default_fallback();

    	if ( $fallback && ! is_wp_error( $fallback ) ) {
    		// Return the newly created fallback post object which will now be the most recently created navigation menu.
    		return $fallback instanceof WP_Post ? $fallback : static::get_most_recently_published_navigation();
    	}

    	return null;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-navigation-fallback.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-navigation-fallback.php#L70)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-navigation-fallback.php#L70-L101)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_navigation_should_create_fallback’, bool $create )](https://developer.wordpress.org/reference/hooks/wp_navigation_should_create_fallback/)

Filters whether or not a fallback should be created.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

| Used by | Description | 
| [WP_REST_Navigation_Fallback_Controller::get_item()](https://developer.wordpress.org/reference/classes/wp_rest_navigation_fallback_controller/get_item/)`wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php` |

Gets the most appropriate fallback Navigation Menu.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_navigation_fallback/get_fallback/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_navigation_fallback%2Fget_fallback%2F)
before being able to contribute a note or feedback.