dtc99987
2014-11-25 07:51
浏览 229
已采纳

如何使用Wordpress在菜单中添加Active类

How to add Class in active menu in wordpress. I have use below Code. but it's not working please help me

                  wp_nav_menu( array(

                        'container' => '',
                        'items_wrap' => '%3$s',
                        'theme_location' => 'primary'

                    ) ); 

图片转代码服务由CSDN问答提供 功能建议

如何在wordpress的活动菜单中添加Class。 我使用下面的代码。 但是它不起作用请帮帮我

  wp_nav_menu(array(
 
'container'=>'',
'itements_wrap'=>'%3 $  s',
'theme_location'=>'primary'
 
));  
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dry9192 2014-11-27 09:51
    已采纳

    please add this code in your nav-menu-template.php file in line number near about 149.

    $item_output .= '<a'. $attributes .' class="'.$classes[0].'" >';
    

    Now on this case your css class apply to href link and you want to just add this class in admin side menu css classes.

    let me know once done.

    已采纳该答案
    打赏 评论
  • dpli36193 2014-11-25 07:55

    Add the following to functions.php

    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
    function special_nav_class($classes, $item){
         if( in_array('current-menu-item', $classes) ){
                 $classes[] = 'active ';
         }
         return $classes;
    }
    

    See the Codex for further reading

    打赏 评论
  • duanchigeng4313 2014-12-04 12:06

    please add this code in your nav-menu-template.php file in line number near about 149.

    $item_output .= '<a'. $attributes .' class="'.$classes[7].'">';
    

    before add this code it will look like this

    <a href="#">Home</a>
    

    after add this code it will look like this

    <a class="current_page_item" href="www.gooole.com">Home</a>
    

    on that your <li> current class is display on link menu item class

    打赏 评论

相关推荐 更多相似问题