Redirect to login when on private page, and when logged in to specific page

I´m using a plugin called “private content login redirect”.

The plugin is actually only containing this piece of code:

    add_action('template_redirect', 'private_content_redirect_to_login', 9);
function private_content_redirect_to_login() {
  global $wp_query,$wpdb;
  if (is_404()) {
    $private = $wpdb->get_row($wp_query->request);
    $location = wp_login_url($_SERVER["REQUEST_URI"]);
    if( 'private' == $private->post_status  ) {
      wp_safe_redirect($location);
      exit;
    }
  }
}

What it does is this: When a non-logged in user is viewing a private page, it redirects them to the log-in page. After they log in, they are taken back to the private page they just visited and can read it.

I would like it to redirect them to log-in page, but when they have logged in, they should be taken to a specific page (ex http://www.testsite.com/start) instead of the private page they visited.

1 Answer
1

from your code you need to change one for redirect user to specific page after login.

Your code :
$location = wp_login_url($_SERVER[“REQUEST_URI”]);

Change it as
$location = wp_login_url (i.e. http://www.testsite.com/start); // pass url of page where you want to redirect user after login

Hope this will help you.

Leave a Comment