daileycon (@daileycon)

Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • @daileycon

    Participant

    I DID IT!!!! Now this adds an edit profile link in my top bar menu only if someone is logged in! Whooo hooo

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

    @daileycon

    Participant

    Ok I found my menu slugs in my functions file.

    // Add Custom Primary Navigation
    function minti_register_custom_menu() {
    	register_nav_menu('main_navigation', 'Main Navigation');
    	register_nav_menu('footer_navigation', 'Footer Navigation');
    	register_nav_menu('topbar_navigation', 'Topbar Navigation');
    }

    but I still get that error when changing primary to topbar_navigation

    // 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 , $args) {
        if (is_user_logged_in() && $args->theme_location == 'topbar_navigation')
            return $menu;
        else
            $current_user = wp_get_current_user();
            $user=$current_user->user_nicename ;
            $profilelink = '<li><a href="/forums/users/' . $user . '/edit">Edit Profile</a></li>';
            $menu = $menu . $profilelink;
            return $menu;
    }

    @daileycon

    Participant

    Maybe the problem is “primary” is not one of my 3 menus? How do I get the menu slugs?

    @daileycon

    Participant

    That code gives me this error in all 3 menus. I just want Edit Profile in the top menu.

    Warning: Missing argument 2 for my_nav_menu_profile_link(), called in /home/wp_5fnr6w/my site/wp-includes/class-wp-hook.php on line 300 and defined in /home/wp_5fnr6w/my site/wp-content/themes/unicon/functions.php on line 749

    If I remove “&& $args->theme_location == ‘primary'” and ” , $args”

    The error goes away but I have Edit Profile in all three menus.

    In reply to: Forum Info

    @daileycon

    Participant

    I was googling for the same thing.

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