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 7.0
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 ) {
return $navigation_post->post_title;
}
}
return $navigation_name;
}