I need to add image for item menu element. I used this documentation that create own code.
add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
function my_wp_nav_menu_objects($items, $args) {
foreach ($items as &$item) {
$icon = get_field('image_icon', $item);
if ($icon !== false) {
$icon_url = $icon['url'];
$icon_alt = $icon['alt'];
$icon_html = '<div class="decor-block_wrapper"><img src="' . esc_url($icon_url) . '" alt="' . esc_attr($icon_alt) . '" /></div>';
$item->title = $icon_html . '<a>url . '">' . $item->title . '</a>';
}
}
return $items;
}
But I got into tag . How to add image before tag without link ? I need something like this
<li>
<div><img src="" /></div>
<a href="">Item</a>
</li>
But now my code criated like this
<li>
<a href=""><div><img src="" /></div></a>
<a href="">Item</a>
</li>