Skip to:
Content
Pages
Categories
Search
Top
Bottom

URL for Menu to Logged-in User's Profile Page


  • TracyByrne
    Participant

    @tracybyrne

    I have been searching for some time and I see a lot of things that seem like answers yet to my headache encased mind, I think things are now flying over my head lol.

    Simply put, what I want to do is create a url that I can put in menu bars or on tops of pages (menu bars better) that will take the logged in user, straight to their own profile. As it stands now, only thing I can do is go to members.

    I’ve seen some fancy code like:

    a href=”<?php bp_loggedinuser_link() ?>”> profile

    and

    function redirect2profile(){
    include_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
    if($_SERVER[‘REQUEST_URI’] == ‘/profile/’ && is_plugin_active(‘buddypress/bp-loader.php’) && is_user_logged_in()){
    global $current_user;
    wp_redirect( get_bloginfo(‘url’) . ‘/members/’. $current_user->user_login . ‘/profile/’);
    exit();
    }
    }
    add_action(‘init’, ‘redirect2profile’);

    When searching for my answers, but none of that helps me with what I want. Once I saw something that instructed use %username% or something such, in the url like http://domain.com/members/%username% … but that ultimately didn’t pan out.

    Does anyone have a simple solution? All I want is a url to the logged in user’s profile 🙂 for a menu bar 🙂

    Thanks, you guys rock!

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

  • bp-help
    Participant

    @bphelp

    @tracybyrne
    Add this to bp-custom.php and it will create a nav menu item that will take the users to their profile.

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

    TracyByrne
    Participant

    @tracybyrne

    @bp-help

    You so seriously ROCK!

    One question though, how do I mod that content (guessing in the wp_nav_menu_items) to tell it exactly which menu or sub menu I want this to display in? This code makes “My Profile” show up on all of my menus (there’s the top of page one, the one under my masthead and the one at the bottom of the page in the footer). Having footer duplicated is great, but having it duplicated in the two top menu’s together looks really bad lol.

    I’d like to begin to seriously understand this code, so please if you can tell me what part of it needs modding and how, so that I can begin to understand and have to ask fewer questions later on, that would be spiffy!

    Again, thanks this was wonderful I’m so excited 🙂


    @mercime
    Participant

    @mercime

    // Filter wp_nav_menu() to add profile link in a specific custom menu e.g. tertiary
    function mme_nav_menu_profile_link($menu, $args) {
        if( is_user_logged_in() && $args->theme_location == 'tertiary' ){
            $profilelink = '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile', 'yourtheme') . '</a></li>';
            $menu = $menu . $profilelink;
        }
        return $menu;
    }
    add_filter( 'wp_nav_menu_items', 'mme_nav_menu_profile_links', 10, 2 );

    Replace ‘tertiary’ with the key name of the menu you want to insert the profile link in.


    TracyByrne
    Participant

    @tracybyrne

    I gave this a go and it made all my menus just dissappear. The name of the menu in question is “Above Header” and that’s what I put in place of “tertiary” … but that file just wiped out all menus lol.

    That’s the name of that menu in the menu’s section … do i have to look somewhere else for it?

    thanks tons!


    @mercime
    Participant

    @mercime

    do i have to look somewhere else for it

    Yes you will have to and it depends on what theme you are using.

    Try ‘above-header’. To confirm, open up your theme’s functions.php file and search for:
    register_nav_menu and you’ll find an array of menus listed for your multiple custom menus. On the same row as or beside ‘Above Header’, find the key used to define that custom menu and replace ‘tertiary’ I posted in code above.


    TracyByrne
    Participant

    @tracybyrne

    you’re not going to believe this but there is VERY little in the functions.php file …

    <?php
    /**
    * Infinity Theme: theme functions
    *
    * @author Marshall Sorenson <marshall@presscrew.com>
    * @link http://infinity.presscrew.com/
    * @copyright Copyright (C) 2010-2011 Marshall Sorenson
    * @license http://www.gnu.org/licenses/gpl.html GPLv2 or later
    * @package Infinity
    * @since 1.0
    */

    /**
    * To Infinity, and beyond! (sorry, had to do it)
    */
    require_once ‘engine/infinity.php’;

    //
    // At this point, Infinity is fully loaded and initialized,
    // and your includes/setup.php has been loaded if applicable.
    //
    // So… get to work! (Unless you don’t roll on Shabbos)
    //

    Das it lol. God I wish I knew what you know 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘URL for Menu to Logged-in User's Profile Page’ is closed to new replies.
Skip to toolbar