I want to display a link on the Frontend, but the URL value changes over time. It'd be very easy for me to just change it manually in the Wordpress menu once (it's also displaying there), and then automatically replace the URL value in the template file link.
But, is there any way to query and echo the URL of a specific Menu Item by ID?
<li id="menu-item-5020" class="menu-item menu-item-type-custom">
<a title="Exhibitions" href="URL">Exhibitions</a>
</li>
I can't seem to find anything in the direction...
I want to display a link on the Frontend, but the URL value changes over time. It'd be very easy for me to just change it manually in the Wordpress menu once (it's also displaying there), and then automatically replace the URL value in the template file link.
But, is there any way to query and echo the URL of a specific Menu Item by ID?
<li id="menu-item-5020" class="menu-item menu-item-type-custom">
<a title="Exhibitions" href="URL">Exhibitions</a>
</li>
I can't seem to find anything in the direction...
Share Improve this question asked Jun 22, 2016 at 12:20 Eric MitjansEric Mitjans 1872 silver badges10 bronze badges1 Answer
Reset to default 3Guessing the only way you get it without loop through the menu, is getting the post meta directly.
Navigation menus are saved as custom post type into wp_posts, so you can get it with get_posts or get_post_meta.
If it's a custom link menu item, the code below should do it. Where $menu_id is you menu item id.
get_post_meta($menu_id, '_menu_item_url', true);
I don't know if it's the best approach, but I think it's a start.