I’m trying to show login link and redirect user to current page after login. The login works fine but the redirect is not working? It always redirects to home page even I can see ?redirect_to='redrect_link'
with login link.
As per WP codex, it should redirect on login:
http://codex.wordpress.org/Function_Reference/wp_login_url
Here is my code:
$link_to_login = '<a href="' . wp_login_url( get_permalink() ) . '" title="Login">Login</a>';
Any reason, why is it not redirecting to current page on login? Any other solution? Thanks
http://wordpress.org/plugins/wordpress-login-redirect/
I’m using this currently, Let me know if it helps.
You’re probably calling
get_permalink()
outside the loop:Solution:
To get the permalink outside of the loop you need to define the
$post
parameter:get_permalink
( int|WP_Post$post
, bool$leavename
= false )Example:
or
Reference:
https://developer.wordpress.org/reference/functions/get_permalink/
https://developer.wordpress.org/reference/functions/get_queried_object_id/
https://developer.wordpress.org/reference/functions/wp_login_url/
P.S. If you’re using AJAX request, see this question: https://wordpress.stackexchange.com/questions/398569/get-the-url-of-the-page-from-which-an-ajax-request-has-been-launched-within-ajax