Jump to content

Redirect Non Logged In Users Except For Blog Posts


godrob

Recommended Posts

Hi Guys,

 

I'd be grateful if one of you could help me out here please?  Basically the code below redirects non-logged in users to my login page unless they access a page specified in the array below.  This all works just fine.  However, what I'd also like to achieve is for non-logged in users to be able to access any blog posts, too.  Any Wordpress guru's able to help me out here?

 

 

        <?php if(!is_user_logged_in() AND (!is_front_page() AND (!is_page( array (49, 57, 1796, 2017, 2951,686, 693, 675, 683, 689, 3063, 3477, 3649, 3989, 2576, 1773, 1784, 2700, 2706,    1791, 2709, 1778, 2703, 4115) ) ) ) ) {
		// wp_redirect('/index.php');
	       $redirect = home_url() . '/wp-login.php?redirect_to=' . urlencode( $_SERVER['REQUEST_URI'] );
	       wp_redirect( $redirect );
		exit;
	}
        ?>

 

Thanks for any help

 

Rob.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.