Site logo

Archived topic

How Do I Get Sidebar Menu Description to Show?

5 replies · Started by Bill on October 22, 2020

Viewing posts 1–6 of 6

Do you know how I can get the Menu Item Description to show in a sidebar? I see a thread on these forums about adding the code to the Primary/Secondary menus, which I added, but the sidebar descriptions don't show. I must need code for the descriptions to show in the sidebar.

Any ideas how to get that showing? ~ Thanks Bill

Hi there,

Not quite sure if I fully understand.

Can you link me to the post you are referring to or an example of what you are trying to achieve?

Thanks :)

https://generatepress.com/forums/topic/adding-description-under-menu/

I would like to use the Menu in the sidebar with the description showing.

Here's what I've done:

1. Appearance >> Menus >> Screen Options >> Description is selected.

2. Menu items created with descriptions

3. Added menu to sidebar

4. Menu title shows

5. Menu description does not show

6. I would like to show the menu description under the menu title

Hi Bill,

You can try this PHP snippet:

function add_nav_description( $item_output, $item, $depth, $args ) {
	$menu_name = 'Your menu name here';
	
		if ( !empty( $item->description) && $menu_name == $args->menu->name ) {
			$item_output = str_replace( $args->link_after . '</a>', '<div class="menu-item-description">' . $item->description . '</div>' . $args->link_after . '</a>', $item_output );
		}

		return $item_output;

}

add_filter( 'walker_nav_menu_start_el', 'add_nav_description', 10, 4 );

Here's how to add PHP - https://docs.generatepress.com/article/adding-php/

Just change the $menu_name value to the name of your menu w/ description.

You then use this CSS for styling:

.menu-item-description {
    margin-left: 20px;
    color: black;
    font-size: 14px;
}

Here's how to add CSS: - https://docs.generatepress.com/article/adding-css/

Let us know if you need further styling.

That worked perfectly. Thanks for your help. I appreciate it. ~ Bill

Nice one.

No problem. :D

This archived topic is closed to new replies.