Insert the image inside the <a> wp_nav_menu tag

I am trying to create a menu in WordPress that has an image above the link and text below the link.

I would like it to be dynamic and use the built-in WordPress menu function. I see that many hacks claim to use CSS to make it a background image, but that doesn't make the image clickable.

Is there a way to get WordPress to add an <img> - or <span> -tag inside an <a> -tag?

+4
source share
1 answer

Try using the options 'link_before' or 'link_after' for wp_nav_menu.

 <?php $args = array( 'link_before' => '<img src="myImage.jpg" />' ); wp_nav_menu($args); ?> 

This inserts something before or after the link text in the menu item.

+3
source

All Articles