0
votes

I am creating a website using WordPress. I am new to it. I have a separate homepage for logged out users and logged in users. Page for logged out users tells them to sign up or log in. And homepage for logged in users show them there profile. So the index.php is the homepage for logged out users. And i have created a different page freevideofy.com/home for logged in homepage.

I use plugin - login redirect to redirect them to freevideofy.com/home when they login in or sign up. And i use plugin - logout redirect to redirect them to freevideofy.com when they logout. But the problem is, if a logged in user closes my website, and again opens it by url - freevideofy.com then they are not automatically redirected to freevideofy.com/home.

So I want if logged in user opens the url - freevideofy.com, then he should be redirected to freevideofy.com/home. I think this function can be used - is_user_logged_in

2
What is your first page? You have to add a code to that page. did you used any page builder?MoeinPorkamel
No. I didnt built any page builder. My first page is the index.phpvishal ranjan
Wordpress Index.php or its a custom file ?MoeinPorkamel
I didnt used any page buildervishal ranjan
So its load your theme index.php file, i will post a answerMoeinPorkamel

2 Answers

0
votes

As you said you didn't used any page builder or set a page as FrontPage ( using settings ), Wordpress should load your theme index.php file as homepage. So you have to edit wp-content/themes/THEMENAME/index.php file and add these two lines of codes:

if (is_user_logged_in() && is_front_page()) {
    wp_redirect(home_url('/home'));
}
0
votes

If you feel a bit more streaky to edit the codes you can use the plugins for redirection also. Since WordPress uses enormous plugins that reduces our work and so i would suggest you to use these plugins for redirection.

Plugin Name 1: Peter's Login Redirect

Redirect users to different locations after logging in and logging out.

Plugin URL: https://wordpress.org/plugins/peters-login-redirect/

Plugin Name 2: Redirection

Redirection is a WordPress plugin to manage 301 redirections and keep track of 404 errors without requiring knowledge of Apache .htaccess files.

Plugin URL: https://wordpress.org/plugins/redirection/

Plugin Name 3: Redirect After Login

Redirect based on Role here.

Plugin URL: https://wordpress.org/plugins/redirect-after-login/

Hope so this will be the easiest method to do redirection based on the login roles and login status as such.

If so you need to do it via function in the WordPress you can do it better in this way.

Function Name: wp_redirect()

Description: Redirects to another page.

Note: wp_redirect() does not exit automatically, and should almost always be followed by a call to exit;

<?php
if(is_user_logged_in())
{
wp_redirect( home_url('/home') ); // This will redirect to the home page which we have created.
exit;
}
else
{
wp_redirect( home_url() );// this will redirect to the site main home page.
exit; 
}
?>