Support » Multisite » [Resolved] Mulisite – How to Get a Users Site/Blog URL

[Resolved] Mulisite – How to Get a Users Site/Blog URL

  • In a multisite setup, when users are visiting a blog/site that is not theirs, I would like to display a link to “Visit My Blog” that takes them to that users “primary” blog.

    I am using WP 3.5 with buddypress installed.

    Currently I am using this:

    <a href="<?php $blog = get_active_blog_for_user( get_current_user_id() );
    $blog_url = $blog->domain?>">Visit My Blog</a>

    But this brings me to the users buddypress profile (domain.com/members/user) not their blog (domain.com/user).

Viewing 12 replies - 1 through 12 (of 12 total)
  • Let’s break it out…

    $blog = get_active_blog_for_user( get_current_user_id() );
    $your_url = $blog->domain;
    <a href="<?php echo $your_url; ?>">Visit My Blog</a>

    Thanks for the response Mika! Unfortunately this takes me to a page not found.

    It takes me to blog.domain.com/members/user/blog.domain.com

    Where their blog is at blog.domain.com/user

    Part of that is you need an http:// in that a href. But…

    Hmm. It’s echoing the blog DOMAIN, as it should. What does this do?

    $blog = get_active_blog_for_user( get_current_user_id() );
    <a href="http://blog.domain.com/<?php echo $blog; ?>">Visit My Blog</a>

    I’m assuming they’re all on the same domain here.

    Didn’t occur to me to add http:// 🙂

    Using your last code removes everything below the code on the page. Using your first code with the http:// brings me to the main blog on the multisite.

    So we are definitely closest with the first code it’s just not picking up the user.

    So maybe something different where $blog=? Sorry, I am not too good with PHP otherwise I’d be more help.

    Using your last code removes everything below the code on the page.


    $user_ID = get_current_user_id();
    $user_blog = get_active_blog_for_user( $user_ID );
    <a href="http://blog.domain.com/<?php echo $user_blog; ?>">Visit My Blog</a>

    Ya it’s weird. The last code did the same thing.

    Here’s a before picture:

    And here’s an after picture:

    View post on imgur.com

    I found this code:

    if(is_user_logged_in()) {
    global $current_user;
      $blogs = get_blogs_of_user( $current_user->id );
         if($blogs) {
         	 foreach ( $blogs as $blog ) {
             echo '<li><a href="http://' . $blog->domain . $blog->path .'">' .  $blog->blogname . '</a></li>';

    It does display the correct URL (yay!), but it only works for the logged in user and displays all users blogs; where I’m looking to only display the users primary blog.

    Here is the post: http://wordpress.org/support/topic/how-to-get-the-urlpath-of-current-users-site?replies=6

    Both images are the same. Where am I looking….?

    Does echo get_active_blog_for_user( get_current_user_id() ); do anything?

    Whoops! Here is the before: http://i.imgur.com/6edHv.png

    Let me try that code I’ll get back to you.

    It removed everything below the member header also.


    We’re silly. Who’s the ‘current user’ when viewing a page?

    Currently it is myladeybugg.

    But I want the “Visit My Blog” to be visible to all users and guests.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Mulisite – How to Get a Users Site/Blog URL’ is closed to new replies.
Skip to toolbar