How to add a subtitle to a menu in WordPress

To add a subtitle to your menu in WordPress, follow these steps

  1. Go to Appearance > Menu and turn on the title attribute.
  2. 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); 
 } 
 
  1. 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>' 
 ));? > 
 
  1. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top