WP_Navigation_Block_Renderer::get_unique_navigation_name
Returns a unique name for the navigation.
Method of the class: WP_Navigation_Block_Renderer{}
No Hooks.
Returns
String. Returns a unique name for the navigation.
Usage
$result = WP_Navigation_Block_Renderer::get_unique_navigation_name( $attributes );
- $attributes(array) (required)
- The block attributes.
Changelog
| Since 6.5.0 | Introduced. |
WP_Navigation_Block_Renderer::get_unique_navigation_name() WP Navigation Block Renderer::get unique navigation name code WP 7.0
private static function get_unique_navigation_name( $attributes ) {
$nav_menu_name = static::get_navigation_name( $attributes );
// 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[ $nav_menu_name ] ) ) {
++static::$seen_menu_names[ $nav_menu_name ];
} else {
static::$seen_menu_names[ $nav_menu_name ] = 1;
}
// If the menu name has been used previously then append an ID
// to the name to ensure uniqueness across a given post.
if ( isset( static::$seen_menu_names[ $nav_menu_name ] ) && static::$seen_menu_names[ $nav_menu_name ] > 1 ) {
$count = static::$seen_menu_names[ $nav_menu_name ];
$nav_menu_name = $nav_menu_name . ' ' . ( $count );
}
return $nav_menu_name;
}