Display path to blog for logged in users in template page.

Which function would I use if I wanted to echo the path to the subsite or folder name and NOT the username?

I have a site using this link below in a page template but if the path & the username are different it does not work? Whats the best alternative to display the path shown in the network settings?

From admin: `<input id=”path” type=”text” value=”/fwhite/” name=”blog[path]”>


It will be displayed for “logged in” users only.

Here is the link in use now:

<a href="http://domain.com/<?php echo $current_user->user_login?>">Your Website</a>

See how that just adds the username to the url link? But I need the actual path instead.

If possible could I trouble you for an example as well?


  • Ash
    • WordPress Hacker

    Hello @george

    I hope you are well today and thanks for asking the question.

    Please use the following code in your theme’s functions.php:

    function go_to_primary_blog(){
    $user_info = get_userdata( get_current_user_id() );
    return get_blogaddress_by_id($user_info->primary_blog);

    Then use the in your template file:

    <a href="<?php echo go_to_primary_blog() ?>">Your website</a>

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.



  • Ash
    • WordPress Hacker

    Hello @george

    I hope you are well today.

    Would you please make sure everyone’s primary blog is different? There is no “users site” or “his site”, the code can pick the primary site of the user.

    So, if you please login with that account, go to My Sites menu from the top left in the admin bar check with one is selected as his primary blog.

    Please let us know.



Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.