I'm adding custom menu items with wp_nav_menu_items filter. The structure is very simple, some "li"s with "a" inside. The point is, is there a way to have wordpress defaults menu calsses (like "menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1995 current_page_item menu-item-1997 active" ecc..) in my custom links? This is the code:

add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' );
function my_nav_menu_profile_link($menu) {  
    if (!is_user_logged_in()) {
        ob_start(); ?>

        <li><a href="<?php echo wp_login_url(); ?>">Login</a></li>

        $login_link = ob_get_contents();

        $menu = $menu . $login_link;
        return $menu;

else {
    $utente = wp_get_current_user();
    $notifiche = bp_notifications_get_unread_notification_count();

    ob_start(); ?>

    <li class="user-menu dropdown"><a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="#"><span><i class="fa fa-user"></i><?php _e($utente->user_login, 'm3_bootstrap') ?><span class="badge"><?php echo $notifiche; ?></span></a></span>
        <ul class="dropdown-menu">
            <li><a href="<?php echo bp_loggedin_user_domain( '/' ); ?>">Bacheca</a></li>
            <li><a href="<?php echo bp_loggedin_user_domain( '/' ); ?>profile">Profilo</a></li>
            <li><a href="<?php echo bp_loggedin_user_domain( '/' ); ?>notifications">Notifiche <span class="badge"><?php echo $notifiche; ?></span></a></li>
            <li><a href="<?php echo bp_loggedin_user_domain( '/' ); ?>settings">Impostazioni</a></li>
            <li><a href="<?php echo wp_logout_url(); ?>">Logout</a></li>


    <?php $profilelink = ob_get_contents();
    $menu = $menu . $profilelink;
    return $menu;

  • Well, what classes do you want? You are tacking new and non-standard links onto the menu. There aren't really any "defaults" for items that you've made up. (Also, the function is a bit over complicated.) – s_ha_dum Jul 22 '15 at 15:01
  • The only one I'm really looking for is the current page one ;) – Marco Jul 23 '15 at 7:34
  • Are these all WordPress pages? You are dealing with Buddy Press (I think) I am not familiar with the details of that system. – s_ha_dum Jul 23 '15 at 13:43
  • Yes, I'm using buddypress, but I don't think it's an important point, because I'm filtering wordpress nav function, and I'm adding custom links. The problem still remains if, instead of buddypress pages, I link to any other page. – Marco Jul 23 '15 at 16:55
  • But the way that buddy press creates the pages does determine how you would identify them. It is relevant. – s_ha_dum Jul 23 '15 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.