In a multisite setup, when users are visiting a blog/site that there are not a member, I would like to display a link to "HOME" that takes them to their "primary" blog.

I know how to determine if a user is or is not a member of a site with the is_current_blog_user() function. The part I am having a problem with is correctly setting the url/path of the "HOME" link to the current users "primary" blog.

Hypothetical Example:

<a href="<?php this_is_the_path_to_users_primary_blog();?>">HOME</a>

I have found the get_active_blog_for_user (http://codex.wordpress.org/Function_Reference/get_active_blog_for_user) function, and this seems to be a good place to start. But I feel as though I must be missing something, and this must be easier than I am making it.


Indeed, get_active_blog_for_user should work.

$blog = get_active_blog_for_user( get_current_user_id() );
$blog_url = $blog->domain... /* or $blog->path, together with $blog->siteurl */


$blog_id = get_active_blog_for_user( get_current_user_id() )->blog_id;
// note: changed "->userblog_id" to "->blog_id" in row above to make it work.
switch_to_blog( $blog_id ); /* switch context */
$home_url = home_url();
restore_current_blog(); /* back */
  • Thank you! I was able to get to the top option to work flawlessly. I appreciate your help. – Rachel Baker Mar 19 '12 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.