WordPress.org

Make WordPress Core

Ticket #13910: 13910-2.diff

File 13910-2.diff, 1.6 KB (added by christophherr, 4 years ago)

Turns markoheijnen's comment into a patch. Adds filter for the title of a navigation menu.

  • src/wp-includes/nav-menu.php

     
    182182}
    183183
    184184/**
     185 * Returns the title of a navigation menu
     186 *
     187 * @since 4.6.0
     188 *
     189 * @param string $theme_location Location of a navigation menu in a theme.
     190 * @return string
     191 */
     192function wp_nav_menu_title( $theme_location ) {
     193        $title = '';
     194        if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
     195                $menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
     196
     197                if ( $menu && $menu->name ) {
     198                        $title = $menu->name;
     199                }
     200        }
     201        /**
     202         * Filter navigation menu title with the location of a navigation menu in a theme.
     203         *
     204         * @since 4.6.0
     205         *
     206         * @param string $title Title of the navigation menu.
     207         * @param string $theme_location Location of a navigation menu in a theme.
     208         */
     209        return apply_filters( 'wp_nav_menu_title', $title, $theme_location );
     210}
     211
     212/**
    185213 * Determines whether the given ID is a nav menu item.
    186214 *
    187215 * @since 3.0.0
     
    770798
    771799                                $menu_item->type_label = __( 'Post Type Archive' );
    772800                                $post_content = wp_trim_words( $menu_item->post_content, 200 );
    773                                 $post_type_description = '' == $post_content ? $post_type_description : $post_content; 
     801                                $post_type_description = '' == $post_content ? $post_type_description : $post_content;
    774802                                $menu_item->url = get_post_type_archive_link( $menu_item->object );
    775803                        } elseif ( 'taxonomy' == $menu_item->type ) {
    776804                                $object = get_taxonomy( $menu_item->object );