• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Menu description in navigation

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Menu description in navigation

This topic is: resolved

Tagged: Menu description, walker_nav_menu_start_el

  • This topic has 8 replies, 2 voices, and was last updated 10 years, 3 months ago by Brad Dalton.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • December 10, 2015 at 6:32 am #173422
    unklee
    Member

    I am modifying the Minimum Pro theme. I have only very basic competency in PHP.

    I want to add the menu descriptions to the secondary navigation menu, which is located in a widget area in the header. I found this discussion on this forum (related to a different theme), and it agreed with what I also found by Googling.

    I added the code to the functions.php file, and the descriptions appear in the menu, and I can style them and make one appear below the other, but the descriptions appear before the menu titles, instead of after. I can't find the way to reverse them.

    The piece of code I presume I have to modify is this:

    return preg_replace('/(<a.*?>[^<]*?)</', '$1' . "<span class=\"menu-description\">{$item->attr_title}</span><br /><", $item_output);

    but I'm afraid I don't really understand Preg-replace and I certainly don't understand all the parameters in this code.

    Is there a simple answer to make the name appear before the description please?

    December 10, 2015 at 10:16 am #173453
    Brad Dalton
    Participant

    Try this ( Untested ) http://www.billerickson.net/code/add-description-to-wordpress-menu-items/


    Tutorials for StudioPress Themes.

    December 13, 2015 at 6:03 am #173656
    unklee
    Member

    Thanks Brad, I'm sorry to delay replying, but I thought I had posted a reply but I must have done something wrong.

    That reference was one of the ones I obtained via Google, and unfortunately, I couldn't get it to work at all - there was still only the menu item name, and not the description. The one I found on this forum was one of only two I found that displayed the description, but both displayed it first.

    For the record, this was the entire code:

    add_filter('walker_nav_menu_start_el', 'description_in_nav_el', 10, 4);
    function description_in_nav_el($item_output, $item, $depth, $args)
    {
    	return preg_replace('/(<a.*?>[^<]*?)</', '$1' . "<span class=\"menu-description\">{$item->attr_title}</span><br /><", $item_output);
    }
    

    Do you, or anyone else, have any ideas how to make the name appear before the description please?

    December 13, 2015 at 6:56 am #173663
    Brad Dalton
    Participant

    This adds it after the menu item name based on my testing http://www.billerickson.net/code/add-description-to-wordpress-menu-items/


    Tutorials for StudioPress Themes.

    December 13, 2015 at 7:13 pm #173721
    unklee
    Member

    Hi Brad, thanks again.

    I tried the code your have referenced again, and it still did nothing. So I've been thinking about why it works for you but not for me.

    My PHP is rudimentary, but it is clear what this code does - it searches for menu links and then adds extra code before the final "/a" tag to display the description as well as the name of the link. I think the "str_replace" function must be correct as it works for you, so I'm thinking the problem must be in the "if" test, which is:

    if( 'header' == $args->theme_location && ! $depth && $item->description )

    Now this is where I start to struggle. I'm guessing what this does is look for any header array which has as its arguments theme_location, $depth and $item->description, and this identifies the menu we want to display. My understanding is that:

    theme_location is set for each menu location, and if not set a default menu is shown.
    $depth is the number of levels in the menu hierarchy.
    $item-> means the item we are looking at is the menu description.

    That all seems straightforward, except those parameters appear in a wp_nav_menu function, and I don't understand what 'header' actually is, where I find it, and how any of those arguments could be "wrong" for me but "right" for you? I also don't understand the "!" in the code.

    Sorry to bug you, but have you any ideas please?

    December 13, 2015 at 7:18 pm #173722
    Brad Dalton
    Participant

    I spent several hours testing different solutuons and this is what i came up with


    Tutorials for StudioPress Themes.

    December 16, 2015 at 4:19 am #173897
    unklee
    Member

    OK, thanks for your help.

    February 1, 2016 at 3:35 am #178023
    unklee
    Member

    Just to close this off, I got it working fine thanks. It was easy, I just had a silly mistake. Thanks again.

    February 1, 2016 at 3:40 am #178025
    Brad Dalton
    Participant

    You're welcome.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble