WordPress.org

Ready to get started?Download WordPress

Forums

CodeFlavors floating menu
[resolved] Add Buddypress profile link (2 posts)

  1. AkumaSeijin
    Member
    Posted 1 year ago #

    Hey guys, I've been trying to get a profile link in my menu by using this code:

    // 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
                        $profilelink = '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('Visit your Awesome Profile') . '</a></li>';
                        $menu = $menu . $profilelink;
                        return $menu;
        }

    But it shows up in both menus...any idea of how to make it just show up in the floating menu?

    http://wordpress.org/extend/plugins/codeflavors-floating-menu/

  2. constantin.boiangiu
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry for the delay, hope I'm not too late. Try this piece of code and let me know:

    /**
     * Filter to add Buddypress profile link
     */
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link', 10, 2 );
    /**
     * Callback function to add Buddypress profile link in floating menu
     *
     * @param string $items - html list of items
     * @param object $args - menu arguments
     */
    function my_nav_menu_profile_link( $items, $args ){
    	$is_floating_menu = CFM_LOCATION == $args->theme_location;
    	if (!is_user_logged_in() || !$is_floating_menu ){
    		return $items;
    	}
    
    	if( function_exists('bp_loggedin_user_domain') ){
    		$profile_link = sprintf('<li><a href="%1$s" title="%2$s">%2$s</a></li>',
    			bp_loggedin_user_domain( '/' ),
    			__('Visit your Awesome Profile')
    		);
           	$items .= $profile_link;
    	}	
    
    	return $items;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.