Wordpress custom login template

I created a custom page in wordpress named custom-login.php and then I set this template to login-chat page from wordpress admin panel, when I visited login-chat page I got login form, I puted my login details and then it redirected me to chat page. But the problem is I can access chat page without doing login.

Code of custom-login.php

$args = array(
'echo'           => true,
'redirect' => site_url( '/chat/ ' ),
'form_id'        => 'loginform',
'label_username' => __( 'Username' ),
'label_password' => __( 'Password' ),
'label_remember' => __( 'Remember Me' ),
'label_log_in'   => __( 'Log In' ),
'id_username'    => 'user_login',
'id_password'    => 'user_pass',
'id_remember'    => 'rememberme',
'id_submit'      => 'wp-submit',
'remember'       => true,
'value_username' => '',
'value_remember' => false



Does anyone know, how to prevent chat page from being accessible without login?


At the top of your chat page template insert the following:

<?php if ( !is_user_logged_in() ) { die(); } ?> 

This function returns false, if the current user is not logged in: is_user_logged_in

Alternatively, if you do not want to modify the chat template, you can fire the login check at page load. Add this to the functions.php of your theme:

// 'template_redirect' is fired before the template is rendered
add_action('template_redirect', 'check_access');

function check_access(){
   // only block the access for the chat page with the slug 'chat'
       // if the user is not logged in: abort
       if ( !is_user_logged_in() ) { die(); }

Need Your Help

How would I go about referencing a document type with RDFa?

semantic-web schema.org semantic-markup rdfa

For a website, I need structured data for a publication content type. On this website, a publication is made of:

Android - Running a background task every 15 minutes, even when application is not running

java android service repeat

I need to build a background task that runs every 10/15 minutes (doesn't really matter, either is good), even when the application is not running.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.