WP_Navigation_Block_Renderer::get_navigation_name
Gets the name of the current navigation, if it has one.
Method of the class: WP_Navigation_Block_Renderer{}
No Hooks.
Returns
String
. Returns the name of the navigation.
Usage
$result = WP_Navigation_Block_Renderer::get_navigation_name( $attributes );
- $attributes(array) (required)
- The block attributes.
Changelog
Since 6.5.0 | Introduced. |
WP_Navigation_Block_Renderer::get_navigation_name() WP Navigation Block Renderer::get navigation name code WP 6.8.1
private static function get_navigation_name( $attributes ) { $navigation_name = $attributes['ariaLabel'] ?? ''; if ( ! empty( $navigation_name ) ) { return $navigation_name; } // Load the navigation post. if ( array_key_exists( 'ref', $attributes ) ) { $navigation_post = get_post( $attributes['ref'] ); if ( ! isset( $navigation_post ) ) { return $navigation_name; } // Only published posts are valid. If this is changed then a corresponding change // must also be implemented in `use-navigation-menu.js`. if ( 'publish' === $navigation_post->post_status ) { $navigation_name = $navigation_post->post_title; // This is used to count the number of times a navigation name has been seen, // so that we can ensure every navigation has a unique id. if ( isset( static::$seen_menu_names[ $navigation_name ] ) ) { ++static::$seen_menu_names[ $navigation_name ]; } else { static::$seen_menu_names[ $navigation_name ] = 1; } } } return $navigation_name; }