redirect - How can force redirected to login for two or more pages to view or access

I have a multiple author wordpress blog. I want to force redirected to login page, if any visitor view or access to spec

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');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744663902a4586631.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信