WordPress Check If User Logged In Or Not

Are you looking to check the user Logged In, to show a message or redirect to any other page? Then here we have a solution. With a simple IF condition, you can check the user where they logged or not. By using this condition you can display the message or redirect any other page in your WordPress website.
Display Message If User is Logged In
Based on user Logged In, you can display the message using the below code.
1 2 3 4 5 |
if ( is_user_logged_in() ) { echo 'Welcome, you are Logged In'; } else { echo 'You are not Logged In'; }; |
Redirect If User is Logged In
If you like to redirect to Home or Login page based on the user Logged In, you can using the below code.
1 2 3 4 5 |
if ( is_user_logged_in() ) { header('Location: https://www.softaox.com/'); // Redirect to Home or Any other Page } else { header('Location: https://www.softaox.com/login/'); // Redirect to LogIn Page }; |
Conclusion:
I hope this will help you to check If User Logged In either you can display a message or redirect. If you have any doubts let me know in the comment section and if you like this article share it with your friends.
LogIn CheckRedirectionWithout Pluginwordpress
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]