Automatically add images to a menu
I am calling a menu into a page, but I want to add images next to the title of the menu items.
I have this code:
ol
?php
$navMenu = wp_get_nav_menu_items(2096); /*/Pass Nav Menu_id or Name*/
$previousMenuParent = $level = 0;
foreach ($navMenu as $menu) {
if($menu-menu_item_parent == 0)
{
$level = 0;
echo 'lia href='. $menu-url .'img src='. get_the_post_thumbnail($menu-ID) .'/ '. $menu-title .'/a';
}
}
?
/li
It works, it is showing the list of the menu items, with title and link, but for some reason, it won't show the post's image next to its title.
I also tried using get_the_post_thumbnail('thumbnail')
instead of get_the_post_thumbnail($menu-ID)
but that won't show an image either, with or without the img src=
I would also prefer to call a post's custom field, which has an image URL, instead of the post thumbnail. Is that possible?
Any help would be greatly appreciated.
Thank you