I'm trying to get an ACF image to display in a WordPress menu. I've followed the documentation on this page https://www.advancedcustomfields.com/resources/adding-fields-menu-items/ I've got a field setup in admin called menu_image this is a Image field type with the return format set to Image URL.
My code to display in the menu on the frontend is like this:
add_filter('wp_nav_menu_objects', 'kodr_wp_nav_menu_objects', 10, 2);
function kodr_wp_nav_menu_objects( $items, $args ) {
// loop
foreach( $items as &$item ) {
// vars
$menu_image = get_field('menu_image', $item);
// append menu_image
if( $menu_image ) {
$item->title .= '<img src="'.$menu_image.'" class="menu-image" alt="menu banner">';
}
}
// return
return $items;
}
But on the frontend it's just returning the image ID rather than the full URL like this:
<img src="101690" class="menu-image" alt="menu banner">
Any ideas why?
Might be
ACFbug but it most definitely looks likemenu_imagereturn format is set toImage ID, notImage URL. You can always leave it as it is and slightly modify your code: