WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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 */
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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