Uncategorized

Redirect Your Custom Post or Pages to login page when viewers are not logged in

Recently one of my client asked me to redirect her viewers ( who wants to check her profile page) to the Login page if the viewers are not logged in. As the profile page are of Custom Posts. I have tried to solve the issue using the following code.

<?php
 $page_id = get_queried_object_id();
if ( !is_user_logged_in() && get_post_type($page_id) =='YourCustomPostType' )
 {
  header('Location: http://www.YourLoginPageURLHere.com');
 }
?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s