Archived topic
Enabling Menu Description(s)
1 reply · Started by antware on September 21, 2021
Hi there guys
I've done a screencast of my issue I'm having as I thought it would be easier to do than try and describe and type it out.
The link is to an mp4 I uploaded to a Google Drive - (see Private Information)
Look forward to any assistance in this regard. Basically just needing Menu Descriptions to be shown on the Mega Menu I'm using. Unfortunately the following filter is not working for me, and I've also checked the Description checkbox under Appearances -> Menus:
// Add new Menu Location
function wpb_custom_new_menu() {
register_nav_menu('nameof-custom-menu',__( 'Custom Menu' ));
}
add_action( 'init', 'wpb_custom_new_menu' );
// Enabling Menu Descriptions
add_filter( 'walker_nav_menu_start_el', 'tu_menu_item_description', 10, 4 );
function tu_menu_item_description( $item_output, $item, $depth, $args )
{
// If we're working with the primary or secondary theme locations
if ( 'primary' == $args->theme_location || 'secondary' == $args->theme_location || 'slideout' == $args->theme_location || 'nameof-custom-menu' == $args->theme_location ) {
$item_output = str_replace( $args->link_after . '</a>', $args->link_after . '</span><span class="description">' . $item->description . '</span></a>', $item_output );
}
// Return the output
return $item_output;
}
You'll notice I've assigned the sub-menus I mention in the video the following location "Custom Menu", but to no avail.
Thanks guys, look forward to your help in this regard.
Hi there,
first thing to check is if a Description appears using your above code on the Primary Menu items, if it does then the code is working and the next thing to check is the theme_location conditions in the code ie.
if ( 'primary' == $args->theme_location || 'secondary' == $args->theme_location || 'slideout' == $args->theme_location || 'nameof-custom-menu' == $args->theme_location )
Currently your last condition is:
'nameof-custom-menu' == $args->theme_location
The nameof-custom-menu needs to match those 'sub menu' items.