How do I get the primary blog url of a user?

I would like to write a function in my theme's functions.php to return the primary blog url of a user on my WPMU network. My definition of primary blog is... the first blog that was created for the user on my network (so it should have the lowest blog id# compared to all other blogs associated with the user).

Can you verify that the code here will work?


function get_primary_blog_url( $user_id ) {
$user_blogs = get_blogs_of_user( $user_id );
$primary_blog_url = $user_blog->site_url();
return $primary_blog_url;


I believe something is wrong here... since get_blogs_of_user( $user_id ); returns an ARRAY of all the blogs id's linked to that user.

Could you kindly show me how I can extract the primary blog ID and use it to call the site_url of that blog?

Thank you in advance!