theme_location ) { foreach ( $item->classes as $value ) { if ( 'menu-item-has-children' === $value || 'page_item_has_children' === $value ) { $title = $title . cambay_get_icon( array( 'icon' => 'angle-down' ) ); } } } return $title; } add_filter( 'nav_menu_item_title', 'cambay_dropdown_icon_to_menu_link', 10, 4 ); /** * Add dropdown icon if primary menu item has children. * * @param string $item_output The menu item output. * @param WP_Post $item Menu item object. * @param int $depth Depth of the menu. * @param array $args wp_nav_menu() arguments. * @return string $item_output The menu item output with social icon. */ function cambay_dropdown_btn_to_menu_item( $item_output, $item, $depth, $args ) { $button = sprintf( '', esc_html__( 'Submenu Toggle', 'cambay' ), cambay_get_icon( [ 'icon' => 'angle-down' ] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped cambay_get_icon( [ 'icon' => 'angle-up' ] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); if ( 'primary' === $args->theme_location ) { foreach ( $item->classes as $value ) { if ( 'menu-item-has-children' === $value || 'page_item_has_children' === $value ) { $item_output .= $button; } } } return $item_output; } add_filter( 'walker_nav_menu_start_el', 'cambay_dropdown_btn_to_menu_item', 10, 4 ); /** * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link and add * some custom markup to match style with wp_nav_menu(). * * @param array $args Configuration arguments. * @return array */ function cambay_page_menu_args( $args ) { $args['show_home'] = true; if ( isset( $args['fallback_cb'] ) && 'wp_page_menu' === $args['fallback_cb'] ) { $args['theme_location'] = 'primary'; $args['menu_id'] = 'menu-container'; $args['menu_class'] = 'menu-container'; $args['before'] = '