The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Using post meta in wp_nav_menu (6 posts)

  1. stevebluck
    Posted 5 years ago #


    I want to display a subtitle (kicker) with each link that is generated with wp_nav_menu().

    I have created a post meta called 'kicker' and was hoping I could do something like the following:

    <?php wp_nav_menu( array('theme_location' => 'main', 'menu_class' => 'sf-menu', 'after' => get_post_meta($post->ID, "kicker", true) )); ?>

    Unfortunately this doesn't work, probably because it can't get the ID, anyone know how I can get this working?


  2. vtxyzzy
    Posted 5 years ago #

    Can you save the ID of the post in a variable while in the loop, and use the variable in the call to get_post_meta?

  3. stevebluck
    Posted 5 years ago #

    Well the wp_nav_menu is not within the loop so how would I get the ID for each menu item that is generated and then use it to get_post_meta?

    Even if I created a loop, how would I matcch a menu item with the correct ID?

    It seems like I would have to create a new SQL query but have no idea how to with the new menu system...

  4. vtxyzzy
    Posted 5 years ago #

    Sorry, I was thinking single.php.

    Perhaps you can use one of the filters called in wp-includes/nav-menu.php.

  5. stevebluck
    Posted 5 years ago #

    nav-menu.php goes straight over my head, way too advanced for me to understand.

    Is anyone able to give me an example of how I could acomplish this?

  6. Net Zero
    Posted 5 years ago #

    I would also be very interested in such a solution.


Topic Closed

This topic has been closed to new replies.

About this Topic