PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 4, 2022

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

 March 04, 2022     login, redirect, wordpress     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing