I’m looking to redirect a user to a specific page if they are not logged in.
So blog.com/welcome
So they can either be viewing this page or wordpress login pages.
I was trying to modify this plugin
http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/
add_action( 'wp', 'dmk_not_loggedin_redirect' );
function dmk_not_loggedin_redirect() {
global $pagenow;
However I am ending up with redirect loops. And I could use some help to stop this.
if ( ! is_user_logged_in() && $pagenow != 'wp-login.php' or 'http://www.blog.co.uk/front' )
wp_redirect( 'http://www.blog.co.uk/front' , 302 ); exit; }
I tried with the action hook
init
but the current post/page information is not available yet. But then,template_redirect
does the job and it only acts on the front-end, login and admin pages work normally.Here, there’s a page with the slug
welcome
, to check for a post useis_single('post-slug')
: