From f4445d75c458eec39b70614b55e1c6efc2164e5b Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 19 Sep 2015 18:06:49 +0000 Subject: [PATCH] Add a `'menu_id'` argument to `wp_page_menu()` so that fallback menus have the same attributes as `wp_nav_menu()`. Props lancewillett, ocean90, wonderboymusic. Fixes #31656. git-svn-id: https://develop.svn.wordpress.org/trunk@34330 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-template.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 7a0f202e2f..f152fbdba0 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -1187,13 +1187,14 @@ function wp_list_pages( $args = '' ) { * arguments. * * @since 2.7.0 - * @since 4.4.0 Added `container`, `before`, `after`, and `walker` arguments. + * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments. * * @param array|string $args { * Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments. * * @type string $sort_column How to short the list of pages. Accepts post column names. * Default 'menu_order, post_title'. + * @type string $menu_id ID for the div containing the page list. Default is empty string. * @type string $menu_class Class to use for the element containing the page list. Default 'menu'. * @type string $container Element to use for the element containing the page list. Default 'div'. * @type bool $echo Whether to echo the list or return it. Accepts true (echo) or false (return). @@ -1211,6 +1212,7 @@ function wp_list_pages( $args = '' ) { function wp_page_menu( $args = array() ) { $defaults = array( 'sort_column' => 'menu_order, post_title', + 'menu_id' => '', 'menu_class' => 'menu', 'container' => 'div', 'echo' => true, @@ -1267,7 +1269,16 @@ function wp_page_menu( $args = array() ) { $menu = $args['before'] . $menu . $args['after']; } $container = sanitize_text_field( $args['container'] ); - $menu = "<{$container} class=\"" . esc_attr( $args['menu_class'] ) . '">' . $menu . "\n"; + $attrs = ''; + if ( ! empty( $args['menu_id'] ) ) { + $attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"'; + } + + if ( ! empty( $args['menu_class'] ) ) { + $attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"'; + } + + $menu = "<{$container}{$attrs}>" . $menu . "\n"; /** * Filter the HTML output of a page-based menu.