You appear to be a bot. Output may be restricted
Description
Add a dropdown icon to top-level menu items.
Usage
$string = twentynineteen_add_dropdown_icons( $item_output, $item, $depth, $args );
Parameters
- $item_output
- ( string ) required – The menu item's starting HTML output.
- $item
- ( WP_Post ) required – Menu item data object.
- $depth
- ( int ) required – Depth of the menu. Used for padding.
- $args
- ( stdClass ) required – An object of wp_nav_menu() arguments.
Returns
string Nav menu item start element.
Source
File name: twentynineteen/inc/icon-functions.php
Lines:
1 to 45 of 45
function twentynineteen_add_dropdown_icons( $item_output, $item, $depth, $args ) { // Only add class to 'top level' items on the 'primary' menu. if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) { return $item_output; } if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) { // Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item. // @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely. $link = sprintf( '<button class="menu-item-link-return" tabindex="-1">%s', twentynineteen_get_icon_svg( 'chevron_left', 24 ) ); // Replace opening <a> with <button>. $item_output = preg_replace( '/<a\s.*?>/', $link, $item_output, 1 // Limit. ); // Replace closing </a> with </button>. $item_output = preg_replace( '#</a>#i', '</button>', $item_output, 1 // Limit. ); } elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) { // Add SVG icon to parent items. $icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 ); $item_output .= sprintf( '<button class="submenu-expand" tabindex="-1">%s</button>', $icon ); } return $item_output; }