确实有一个过滤器,walker_nav_menu_start_el
会帮你处理的!
以该代码为例:
function wpse356896_filter_primary_nav_menu_dropdown( $item_output, $item, $depth, $args ) {
// Only for our primary menu location.
if ( empty( $args->theme_location ) || \'primary-menu\' !== $args->theme_location ) {
return $item_output;
}
// Add the dropdown for items that have children.
if ( ! empty( $item->classes ) && in_array( \'menu-item-has-children\', $item->classes ) ) {
return $item_output . \'<span class="dropdown"><img src="chevron.svg"></span>\';
}
return $item_output;
}
add_filter( \'walker_nav_menu_start_el\', \'wpse356896_filter_primary_nav_menu_dropdown\', 10, 4 );