Search code examples
phpwordpresswp-nav-menu-item

How to add php code inside link_before inside wp_nav_menu()?


I want to add this line <img src="<?php field('text') ?>" alt="" /> inside

wp_nav_menu( array $args = array( 'link_before' => 'ADD_CODE_HERE' ));

but it doesn't work because link_before is for text. Is there any way to add this code?


Solution

  • Try like this:

    wp_nav_menu( array( 'link_before' => '<img src="'. field("text") .'" alt="" />' ));
    

    If your field("text") has proper value then the image will show up.