Jump to content
jimwise68

code to link back to user profile on multisite

Recommended Posts

This is probably a very simple fix for someone but I can't get it to work.

I have a wordpress multisite using a bought theme (which has a basic chat function) and a bought chatroom plugin. The theme and plugin clash and the result is a couple of functionalities on the theme don't work. As a work around I crated the multisite so everything works as it should.

the problem I have is when trying to go back to main site from sub-site to access user profile.

I have found this piece of code, which apparently should work but it doesnt.

Can anybody throw any light onto why not.

 

<?php $current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
    wp_redirect( 'https://mysite.co.uk/profile/'.$current_user->user_login.);  class="button"><?php _e('My Profile', 'mytheme'); ?>
    exit;
} else {
    echo "https://mysite.co.uk";
}
?>

 

the profile page url is made on the fly and is listed as: https://mysite.co.uk/profile/username

 

Any help greatly appreciated it.

:)

 

Share this post


Link to post
Share on other sites

Are you trying to create a link or do a redirect? You're attempting both in there and that won't work.

Share this post


Link to post
Share on other sites

HI requinix,

 

I'm just trying to link back to the mainsite to view profile. I don't care if it is a link or redirect, whichever is easier to do from the button.

Share this post


Link to post
Share on other sites

If you want a link then create a link.

<a href="https://mysite.co.uk/profile/<?=$current_user->user_login?>">Link text here</a>

 

Share this post


Link to post
Share on other sites

haha you say it so matter of factly, been trying to do that and couldn't get it to work.

 

thank you for helping with my issue, have a wonderful xmas

 

:)

Share this post


Link to post
Share on other sites

Then you need to find the problem and fix it. What's your code now?

Share this post


Link to post
Share on other sites

Hi Requinix

that solved it, i edited my code to:

 

    <div>
    <?php $current_user = wp_get_current_user(); ?>
    <a href="https://mainsite.co.uk/profile/<?=$current_user->user_login?>" class="button primary"><?php _e('My Profile', 'mytheme'); ?></a>
    </div>

 

...and it works perfectly   :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.