I have a WordPress Multi Site installation and several blogs. On the frontpage (domain.com) I have a login form and when the user is logged in, it shows two links at the moment (Admin Panel and Log out). But I also want to include a link that goes to the current blog site of the user, eg: blog.domain.com.

<li class="showblog"><a href="https://wordpress.stackexchange.com/questions/123750/<?php <some code> ?>">Show blog</a></li>

2 Answers
2

try use this function,,

function get_primary_blog_url($id=null) {
  // is there a user to check?
  global $current_user;
  $user_id = (null != $id ) ? $id : $current_user->ID;

  if ( isset( $user_id ) ) {
    // Get the blogs of this user
    $user_blogs = get_blogs_of_user( $user_id );

    // Get the URL of the blog
    foreach ( $user_blogs AS $user_blog ) {
      if ( $user_blog->userblog_id != BLOG_ID_CURRENT_SITE ) { 
        return $user_blog->siteurl;
      }
    }
    // If user has no blog, return to the homepage.
  } else {
    return home_url();
  }
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *