Friday, March 4, 2022

[FIXED] Wordpress : Redirect when user is logged in & on login page

Issue

I'm tring to redirect my logged users supposing that they will somehow end up on the login page (Redirection to the member area).

Here is my code, located in my functions.php file :

if ( is_user_logged_in() && is_page(ID) ) {
    wp_redirect('mydomain.com/my-member-area/');
    exit;
}

So, I tried putting the page ID, or the slug between '', but it won't work.

And when I remove the && is_page(ID) part, redirection works on every single page (logically).


Solution

Try:

if ( is_user_logged_in() && get_the_ID() == 6005 ) {
    wp_redirect('mydomain.com/my-member-area/');
    exit;
}


Answered By - manishie

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.