Support » How-To and Troubleshooting » Using post meta in wp_nav_menu
6 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?
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?
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…
Sorry, I was thinking single.php.
Perhaps you can use one of the filters called in wp-includes/nav-menu.php.
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?
5 years, 10 months ago
I would also be very interested in such a solution.