Skip Navigation

[Resolved] Redirect user to another page if they are logged in

This thread is resolved. Here is a description of the problem and solution.

Problem:
Redirect user to another page if they are logged in

Solution:

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/redirect-user-to-another-page-if-they-are-logged-in/#post-1268779

Relevant Documentation:

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by StanleyT8485 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1267493

I want to redirect user to another page if they are logged in.

Here is what I have so far.

If logged in = Redirect to another page.
If not logged in = Show this form.

[wpv-conditional if="( '[wpv-current-user info='logged_in']' eq 'true' )"]
Redirect user to another page.
[/wpv-conditional]
[wpv-conditional if="( '[wpv-current-user info='logged_in']' eq 'false' )"]
[cred_user_form form="teardrop-flag-form"]
[/wpv-conditional]
#1267529

I manage to solve it with this code.

function redirect_to_specific_page() {

	if ( is_user_logged_in() && is_page( 1012 ) ) 
	{
		wp_redirect( get_permalink( 44 ) ); 
  		exit;
    }
}

add_action( 'template_redirect', 'redirect_to_specific_page' );

Not the most efficient way but it gets the job done.

Now I need to duplicate this for each page that I have because the redirect is unique for each page.

#1267719

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

It seems you have used the correct hook now you need to add if and else conditions within that hook to check with your multiple pages and add redirection accordingly.

#1268675

How would use the else function?

Currently, I am using Conditional Output if isn't logged in.

[wpv-conditional if="( '[wpv-current-user info='logged_in']' eq 'false' )"]
[cred_user_form form="teardrop-flag-form"]
[/wpv-conditional]

What do you think?

#1268779

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no else condition but you should check if value is equal to or not equal to.

For example:

[wpv-conditional if="( '[wpv-current-user info='logged_in']' ne 'false' )"]
[cred_user_form form="teardrop-flag-form"]
[/wpv-conditional]
#1271197

My issue is resolved now. Thank you!