[Resolved] How Do I Get Sidebar Menu Description to Show?

Home Forums Support [Resolved] How Do I Get Sidebar Menu Description to Show?

Home Forums Support How Do I Get Sidebar Menu Description to Show?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1500279
    Bill

    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

    #1500362
    Leo
    Staff
    Customer Support

    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 ๐Ÿ™‚

    #1500375
    Bill

    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

    #1500680
    Elvin
    Staff
    Customer Support

    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.

    #1501161
    Bill

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

    #1503838
    Elvin
    Staff
    Customer Support

    Nice one.

    No problem. ๐Ÿ˜€

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.