How To Create WordPress Members Only Pages

Sometimes we need to make our pages “members only”. Let me inform you that this is just a quick method of make pages “members only” section of your website. That means those pages will authorize only logged in users. It can be make easily, lets have a look..

Create a Custom Template Page

For this first we’ve to create a custom template page in our theme folder. Create a page name “member.php”. Open it with an editor and write those codes for making a custom template page.

<?php
/*
Template Name: Member Page
*/

First of all you need to add this code given below to check the user logged in or not

<?php if ( $user_ID ) : // if logged in 

If the user not logged in the redirect to the wp-login.php page.

< ?php else : // if not logged in go to login page 

	$url = '/wp-login.php';
	header("Location:$url"); 

endif; // end if logged in
?>

This is very simple. Isn’t it !!!