Take the tour ×  In my application, users have to login first
before accessing the website.  So now what I am doing, I have
created one custom login page.  How can I redirect a user to the
login page if he/she is not logged in yet.  Should i customize
wp-login.php for login? Which is better way, 1. Redirect user to
login page or 2. wp-login.php  share|improve this question add
comment  2 Answers  up vote 2 down vote accepted  You can use
the following action to redirect all traffic to that login page.
You will need to specify the page name and the page slug.
add_action('wp', 'wpse_41699_wp', 0); function wpse_41699_wp(){
$url = get_bloginfo('home').'/login';         header('HTTP/1.1
403 Forbidden');         header("Location: $url");  Also, you
can download the plugin version for this answer here.
share|improve this answer Thanks Brian Fegter –  Ajay Patel Feb
9 '12 at 6:48 add comment  There are many ways to do this, you
can try something like this:  $post = $wp_query->post;  if (
is_user_logged_in(