To add a subtitle to your menu in WordPress, follow these steps
- Go to Appearance > Menu and turn on the title attribute.
- Add the following code to functions.php
function attribute_add_nav_menu($item_output, $item){
return preg_replace('/(<a.*? >[^<]*?) </', '$1' . "<span class="sub-title">{$item->attr_title}</span><", $item_output);
}
- Add a parameter when outputting the menu; you don’t have to include it if you don’t need the span wrap:
<?php wp_nav_menu(array(
'menu' => 'header-menu-1',
'link_before' => '<span class="main-title">',
'link_after' => '</ span>'
));? >
- The order of the spans will change, so use flex order to adjust the order.
These are the steps to add a subtitle to a menu in WordPress.