How to redirect non logged in users to Login page on Wordpress?

后端 未结 4 1012
既然无缘
既然无缘 2020-12-22 06:07

I know this is a question asked million times but I can\'t find an answer that is either fitting the version of Wordpress now and/or my particular case.

I have a Wor

4条回答
  •  猫巷女王i
    2020-12-22 06:18

    What you want it to check if the user is not currently trying to login or register, if not redirect them to whatever page you'd like.

    if ( !is_user_logged_in() && !is_page( 'login' ) && ! is_page('register') ) {
       //redirect user, create account with them, do a hoola-hoop
    }
    

    Be sure to place this code in your page file before get_header();

提交回复
热议问题