Skip to:
Content
Pages
Categories
Search
Top
Bottom

Specify Menue – Add “edit profile”


  • Afu24
    Participant

    @afu24

    Hi,

    Is used the code snippet from the codex and it worked fine.

    How could I modify the code to choose a specific menu?

    E.g. primary oder secondary. Actually “Edit Profil” is shown in all my menues and I just want to have it on my Primary Menu.

    // Filter wp_nav_menu() to add profile link
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' );
    function my_nav_menu_profile_link($menu) {
        if (!is_user_logged_in())
            return $menu;
        else
            $current_user = wp_get_current_user();
            $user=$current_user->user_login ;
            $profilelink = '<li><a href="/forums/users/' . $user . '/edit">Edit Profile</a></li>';
            $menu = $menu . $profilelink;
            return $menu;
     
    }

    Layout and functionality – Examples you can use

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robkk
    Moderator

    @robkk

    you would need to do something like this.

    Since it is hard to guess what your menu’s theme location is , i just put primary.

    This does work in some default themes like Twentyfourteen though.

    add_filter('wp_nav_menu_items','rk_bbp_menu_profile_link', 10, 2);
    function rk_bbp_menu_profile_link( $items, $args ) {
        if( is_user_logged_in() && $args->theme_location == 'primary')  {
    		
    	$current_user = wp_get_current_user();
            $user = $current_user->user_login ;
    	$profilelink = '<a href="/forums/users/' . $user . '/edit">Edit Profile</a>';
            $items .=  '<li>' . $profilelink .  '</li>';
    
    	}
        return $items;
    }

    Afu24
    Participant

    @afu24

    @Robkk awesome, that is exactly what I was looking for. Thanks!!!

    Is there an option to set the position order of the menu item?
    Now its positioned after the normal menu items added at the theme design/menues.


    Robkk
    Moderator

    @robkk

    yeah that sounds about right that it should do that, and you probably could position it but i haven’t tried messing with that yet.

    where do you want the link exactly??

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar