- This topic has 6 replies, 2 voices, and was last updated 6 years, 9 months ago by
Tom.
-
AuthorPosts
-
August 12, 2016 at 8:29 am #217686
Max
I am developing a WP site locally on Xampp.
I am using the following code to add a styled login/out button to the sidebar:
add_shortcode( 'my_login', 'my_login' ); function my_login() { if ( is_user_logged_in() ) return '<a href="'.wp_logout_url( get_permalink() ).'" title="Logout" class="button login">LOG OUT</a>'; else return '<a href="'.wp_login_url( get_permalink() ).'" title="Login" class="button login">LOG IN</a>'; }
My site has 6 pages linked to the main nav. One is for the blog and another is a bbpress forum. If I login/out on 4 of these pages the code works as expected. That is if I visit the page then log in I am returned to that page. If I log out on that page I am returned to it also.
However, when on the blog main page, or a blog post, and I log in I am taken (always) to the oldest post in the blog (the one that displays last on the blog main page) What ever page I log out from in the blog same occurs. I am taken to the last post.
Same problem occurs if I am on the forum index page or a forum topic. When I log in I am taken (always) to the forum at the bottom of the forum index. What ever forum page I log out from same problem occurs.
I have tried deactivating all plugins and the bug remains so it is not plugin related.
Basically I just want my login/out to function as it should. Whatever page a person is on when they log in they are taken back to that page.
Any help anyone can provide to resolve this is greatly appreciated.
Thank in advance for any assistance.
Kind Regards
Max
August 12, 2016 at 9:14 am #217702Tom
Lead DeveloperLead DeveloperHi Max,
GP doesn’t change any permalink settings.
I’m not sure why this would be happening. It’s most likely that get_permalink() is grabbing the URL of the first item in the loop (latest blog post etc..).
Have you tried asking over on Stackoverflow? They’re awesome, and will most likely have an answer for you.
August 12, 2016 at 10:58 am #217722Max
Posted on Stack and Wp support already. Posted here out of desperation.
August 12, 2016 at 11:00 am #217726Max
Its not a child theme issue either. Problem remains if I revert back to GP theme.
August 13, 2016 at 12:15 am #217816Tom
Lead DeveloperLead DeveloperLooked around a bit and found this: https://core.trac.wordpress.org/ticket/9963#comment:6
August 13, 2016 at 12:40 am #217819Max
Yes.
I found this at 4am this morning just before collapsing into bed.
$loginout = '<li class="nav-menu" class="menu-item">' . wp_loginout($_SERVER['REQUEST_URI'], false ) .
It works. And it also runs a lot faster than the permalink option.
I am not sure what the “false” attribute is for though?
Sorry for bothering you so much here in these forums. I am old and lost my job nearly a year ago due to bad health. I am trying to start something online.
Your help and patience (with my often non related GP questions) is appreciated greatly.
Kind Regards
Max
August 13, 2016 at 9:07 am #217900Tom
Lead DeveloperLead DeveloperGlad you got it working.
Happy to help when I can 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.