admin管理员组

文章数量:1391991

I have a multiple author wordpress blog. I want to force redirected to login page, if any visitor view or access to specific pages. example : If user visit to specific page like, www.mysite/author-terms/, thereafter redirect to www.mysite/wp-admin.php/. Thanks in advance.

We have created a page in our blog called 'Instructions for Contributors'. If any visitor copied the link to this page ('Instructions for Contributors') and opens it directly in the browser. So it will open, and anyone can read the instructions given in it. Want to limit it to the blog's contributors. If a visitor tries to open the 'Instructions for Writers' page link directly, then it is redirected directly to the login page.

I have a multiple author wordpress blog. I want to force redirected to login page, if any visitor view or access to specific pages. example : If user visit to specific page like, www.mysite/author-terms/, thereafter redirect to www.mysite/wp-admin.php/. Thanks in advance.

We have created a page in our blog called 'Instructions for Contributors'. If any visitor copied the link to this page ('Instructions for Contributors') and opens it directly in the browser. So it will open, and anyone can read the instructions given in it. Want to limit it to the blog's contributors. If a visitor tries to open the 'Instructions for Writers' page link directly, then it is redirected directly to the login page.

Share Improve this question edited Mar 16, 2020 at 10:13 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Mar 16, 2020 at 6:08 Satya ComputersSatya Computers 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You can check, if a user is logged in with is_user_logged_in() and for certain page with is_page(). If conditions are met, redirect the user with wp_redirect().

function redirect_non_loggedin_user() {
  // if user is on certain page and not logged in
  if ( ! is_user_logged_in() && is_page('instructions-for-contributors') ) {
    // redirect to login page and back after login
    wp_redirect( wp_login_url( get_permalink() ) );
    exit;    
  }  
}
add_action('template_redirect', 'redirect_non_loggedin_user');

本文标签: redirectHow can force redirected to login for two or more pages to view or access