Wordpress: Adding a variable inside wp_nav_menu

巧了我就是萌 提交于 2020-01-07 08:47:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!