jimwise68 Posted December 23, 2018 Share Posted December 23, 2018 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. Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/ Share on other sites More sharing options...
requinix Posted December 23, 2018 Share Posted December 23, 2018 Are you trying to create a link or do a redirect? You're attempting both in there and that won't work. Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/#findComment-1563062 Share on other sites More sharing options...
jimwise68 Posted December 24, 2018 Author Share Posted December 24, 2018 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. Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/#findComment-1563078 Share on other sites More sharing options...
requinix Posted December 25, 2018 Share Posted December 25, 2018 If you want a link then create a link. <a href="https://mysite.co.uk/profile/<?=$current_user->user_login?>">Link text here</a> Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/#findComment-1563081 Share on other sites More sharing options...
jimwise68 Posted December 25, 2018 Author Share Posted December 25, 2018 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 Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/#findComment-1563088 Share on other sites More sharing options...
requinix Posted December 25, 2018 Share Posted December 25, 2018 Then you need to find the problem and fix it. What's your code now? Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/#findComment-1563089 Share on other sites More sharing options...
jimwise68 Posted December 27, 2018 Author Share Posted December 27, 2018 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 Quote Link to comment https://forums.phpfreaks.com/topic/308065-code-to-link-back-to-user-profile-on-multisite/#findComment-1563114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.