问题
I am trying to add a variable inside wp_nav_menu, I am not sure how to do it, please help me! Here is a snippet of the code:
wp_nav_menu(array(
'menu' => 'Main Menu',
'theme_location' => 'Main Menu',
'container' => null,
'container_class' => '',
'menu_id' => 'header-menu',
'menu_class' => '',
'before' => '<span class="text1">',
'after' => '</span><span class="text2"><a href="">' . the_title($post->ID) . '</a></span>',
));
PLEASE HELP ME!
回答1:
Have a look at this tutorial. It's quite likely to answer your question and more
回答2:
Is this what you mean? You may have to explain a little further, but this is how you'd add some additional values to wp_nav_menu
.
wp_nav_menu(array(
'MyItem' => 'My Value', // <--new item
'MyotherItem' => 'My Other Value', // <--other new item
'menu' => 'Main Menu',
'theme_location' => 'Main Menu',
'container' => null,
'container_class' => '',
'menu_id' => 'header-menu',
'menu_class' => '',
'before' => '<span class="text1">',
'after' => '</span><span class="text2"><a href="">' . the_title($post->ID) . '</a></span>',
));
回答3:
Try this this will add URL
wp_nav_menu( array( 'theme_location' => 'header-menu','menu_class' => 'drop', 'container' => 'nav', 'link_before' => '<span></span>') );
If you want it this way url
wp_nav_menu( array( 'theme_location' => 'header-menu','menu_class' => 'drop', 'container' => 'nav', 'link_before' => '<span>', 'link_after' => '</span>') );
来源:https://stackoverflow.com/questions/10403837/wordpress-adding-a-variable-inside-wp-nav-menu