• Resolved valuser

    (@valuser)


    Is it possible to have link for “My Site” (logged in user) on sites in a WordPress Network so that no matter which site the user is on (if he/she is logged in) they can quickly get back to their own site ?

    If it is, could you please enlighten me.

    Tried
    <a href= "<?php $user=wp_get_current_user(); echo $user->user_url;?>">My Site</a>

    but thats not it. Any help much appreciated

Viewing 9 replies - 1 through 9 (of 9 total)
  • There’s a link to a user’s sites in the admin bar. Did you turn it off?

    Thread Starter valuser

    (@valuser)

    Yes. If possible I’d prefer to do without the admin bar. Can this (the “My Site” link) be done ?

    Have a look at the code in wp-admin/my-sites.php

    Thread Starter valuser

    (@valuser)

    Thanks, Andrea.

    Tried lots of variations from that source. Eventually thought <a href="<?php echo home_url( '/' ); ?>"><?php $user_blog->blogname; ?></a> would work but no luck.

    Not a coder. Just a mediocre Cut & Paster.

    I’ve come up with this convoluted piece :

    <a href="<?php
    echo home_url( '/' );?>"
    <?php
    global $current_user;
    get_currentuserinfo();
    $user_id =  $current_user->ID ;
    $user_blogs = get_blogs_of_user( $user_id );
    foreach ($user_blogs AS $user_blog) {$user_blog->blogname;}
    echo home_url( '/' );echo $user_blog->blogname;
    ?>

    While this returns https://your domain.com/logged_in_user_site_name

    There are some problems.

    1. Surely there is a neater way ?

    2.The logged_in_user_site_name that is returned is capitalized. (If the site name is Techwizard, it returns Techwizard but the link is actually in lower case https://your domain.com/ techwizard/) so the returned blogname would have be be uncapitalized. Help!

    3) It would have be conditional on a user being logged in, as otherwise it will return an error. Help!

    4) I don’t know how to put the tag “My Site” on the above convolution. Help!

    BTW I tried omitting the first and the second `echo home_url( ‘/’ );?’ but it didn’t appear to work without both.

    Any better ideas or improvements on the above would really be appreciated

    Not a coder. Just a mediocre Cut & Paster.

    I code like I speak French, and that joke goes over like gangbusters in Montreal. has ’em rolling in the aisles.

    (In other words, me too.)

    3 – is_user_logged_in

    Actually, with all this work (no I can’t think of a neater way) why *not* use the admin bar? It’s built in!

    Thread Starter valuser

    (@valuser)

    Thanks. that part finis!
    2 to go

    Thread Starter valuser

    (@valuser)

    Almost. Could this be left open for awhile. Somebody might come with something to just get the tag in – rather than have the tag and the whole url.

    <a href="<?php
    echo home_url( '/' );?>"
    <?php
    if ( is_user_logged_in() ) {
    global $current_user;
          get_currentuserinfo();
         $user_id =  $current_user->ID ;
    $user_blogs = get_blogs_of_user( $user_id );
    foreach ($user_blogs AS $user_blog) {$user_blog->blogname;}
    echo "<h6>Your Site</h6>";
    echo home_url( '/' );echo strtolower($user_blog->blogname);
    }
    ?>
    </a>

    Thread Starter valuser

    (@valuser)

    To complete this Code below appears to work.

    <?php
    if ( is_user_logged_in() ) {
    global $current_user;
          get_currentuserinfo();
         $user_id =  $current_user->ID ;
    $user_blogs = get_blogs_of_user( $user_id );
    foreach ($user_blogs AS $user_blog) {$user_blog->siteurl;}
    $link = $user_blog->siteurl;
    $title = "My Site";
    $var  = "<a href='$link' target='_blank' title ='in new tab'>$title<a/>";
    echo "<h3>$var</h3>";
    }
    ?>

    target blank not necessary

    Thread Starter valuser

    (@valuser)

    Slight correction to the above. The inclusion of “break;” ensures the link is to the users primary blog.

    <?php
    if ( is_user_logged_in() ) {
    global $current_user;
          get_currentuserinfo();
         $user_id =  $current_user->ID ;
    $user_blogs = get_blogs_of_user( $user_id );
    foreach ($user_blogs AS $user_blog) {
    $user_blog->siteurl;
    break;
    }
    $link = $user_blog->siteurl;
    $title = "My Blog";
    $var  = "<a href='$link' target='_blank' style='color: blue;' title ='in new tab'>$title<a/>";
    echo "<h3>$var</h3>";
    }
    ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘A Link for "My Site" (logged in user)’ is closed to new replies.