开发者

Insert an image inside the <a> tag of wp_nav_menu

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

I wo开发者_开发知识库uld like it to be dynamic and using the built-in WordPress menu function. I see so many hacks stating use CSS to make it a background image yet that doesn't make the image clickable.

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


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

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

This will insert something either before or after the link text of the menu item.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜