Internal links to logged in user

I was wondering how people go about creating links to logged in users profile / messages etc?
I have a multi site setup and I want to create a link on site 2 which takes the user to their profile on site 1.
I would also like to create a custom "My Stuff" menu link which takes users to there profile / messages etc.

Has anyone done this?


  • Patrick
    • Support Monkey

    Hiya @mark_bonito

    We can rule out using the native custom links feature under "Appearance" > "Menus" as that cannot process php functions. Which is what you're going to need for this.

    But first, are you running BuddyPress on that network? Or are you using our Messaging plugin for messages?

    Do you want to link to profiles in the backend of site 1, or are the profiles on the front-end?

  • mark_bonito
    • Site Builder, Child of Zeus

    Just wondering if anyone else has come across this? I was hoping there would be a simple
    style link that I could put into the URL

    My multisite setup needs to link to a messaging page also.

    Hope someone has an idea?

    Kind regards

  • Patrick
    • Support Monkey

    Hey @mark_bonito

    Sorry for not getting back to you on this earlier... weekend :slight_smile:

    As I mentioned, you cannot do this with WordPress custom menus. That cannot handle php code or query values in URLs.

    You would need to either hardcode these links in your header.php file, or create shortcodes to insert them wherever you like.

    I like the second option for its flexibility. A really cool plugin that can help you create any shortcode you like is Shortcode Exec PHP:

    If you set the shortcodes to "Global" in the plugin settings, you can use them throughout your network, even in widgets if your theme allows it.

    Here's an example of what you could use in that plugin to create a shortcode that links to the BuddyPress profile of the logged-in user:

    if (is_user_logged_in()):
    echo '<a href="';
    echo (bp_loggedin_user_domain() . "profile");
    echo '">Update your Profile</a>';
  • mark_bonito
    • Site Builder, Child of Zeus

    Thanks Patrick! That is a great plugin indeed!

    Will I be able to use the shortcode in a URL? from what I think, you will say no, it works with links throughout the site.

    Here is the main problem I have. Site 2 has a field link I need to fill in which takes the members to the "contact member" page. It is an auction site so this feature is pretty important when people need to ask questions etc.
    So built in to the theme is "contact member" button which simply directs the user to the email page (on site1)

    Perhaps I can put the short code into the php file of site2? But I understand that is not a wpmudev theme so I should contact them.

    I shall think and try a few things, but you showing me that plugin has certainly been a massive help! So thanks!
    Any ideas or further suggestions are welcome ofc :slight_smile:

    Kind Regards

  • Patrick
    • Support Monkey

    Hi again @mark_bonito

    While you can use shortcodes when adding code directly to files/templates, you don't need to if you're coding the functions yourself. Just use the straight php like so:

    <?php if (is_user_logged_in()): ?>
    <a href="(bp_loggedin_user_domain() . 'profile')">Your Profile</a>
    <?php endif; ?>

    However, the above function is not going to work for your use-case. You would likely need to create a function that gets the ID of the user who posted the auction item, then auto-populate the send-to email field/function.

    I wouldn't know how to do that though myself. Perhaps another member would like to contribute here?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.