0

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

9
  • What is your first page? You have to add a code to that page. did you used any page builder? Commented Sep 11, 2016 at 17:14
  • No. I didnt built any page builder. My first page is the index.php Commented Sep 11, 2016 at 17:17
  • Wordpress Index.php or its a custom file ? Commented Sep 11, 2016 at 17:20
  • I didnt used any page builder Commented Sep 11, 2016 at 17:21
  • So its load your theme index.php file, i will post a answer Commented Sep 11, 2016 at 17:22

2 Answers 2

1

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')); } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response. Where should i place the code, in header or in index.php
I dont want logged in users to see the the freevideofy.com page which says them to sign up. For logged in users, there is a separate homepage - freevideofy.com/home. Login redirect plugins only redirect users when they log in... But when logged in users visit the url freevideofy.com they see the page which tell them to sign up
0

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; } ?> 

4 Comments

@vishal ranjan. try placing the is_user_logged_in() conditon in the header.php file so that it will redirect to the freevideofy.com/home if the user is logged in or else it will redirect to the freevideofy.com/ of the site. Since header.php will load first for all the page load actions
@vishal ranjan. Have you obtained the output as required bro:) If you need more helps let me know over here and we shall resolve the rest. Or else you shall +1 vote and accept the answer as best one since it might be useful for other developers who face the same issue while development :)
I dont want logged in users to see the the freevideofy.com page which says them to sign up. For logged in users, there is a separate homepage - freevideofy.com/home. Login redirect plugins only redirect users when they log in... But when logged in users visit the url freevideofy.com they see the page which tell them to sign up
@vishalranjan. Have you set this page freevideofy.com as the home page or what in your Wordpress Dashboard under Settings->Reading Menu

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.