add_filter( 'nav_menu_item_title', [ $this, 'add_expand' ], 10, 4 ); } /** * @param string $title The menu item's title. * @param object $item The current menu item. * @param array $args An array of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. * @return string $title The menu item's title with dropdown icon. */ public function add_expand( $title, $item, $args, $depth ): string { if( $args->theme_location === 'primary' || $args->theme_location === 'secondary' ) { foreach ( $item->classes as $value ) { if( $value === 'menu-item-has-children' || $value === 'page_item_has_children' ) $title .= Snippets::svg_icon( 'expand' ); } } return $title; } }