Hide WordPress login page without plugin
- Article
- Comment
Hide WordPress login page without plugin. This is a simple way to prevent User access your WordPress default login page. Some times you need to prevent your site users to access your admin section.
The action Hook “ login_init ” helps you to run a snippet before loading login page. So the follwoing code help you to redirect the login page to 404 page. I mean page not found error page.
function kv_no_loginpage_access() { global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 ); exit(); } add_action( 'login_init' , 'kv_no_loginpage_access' ); add_action( 'admin_init' , 'kv_no_loginpage_access' );
So making your WordPress hard to prevent user access. Instead of the 404 page. you can redirect them to a custom login page to get some front end your rights. May be you have premium things. which you want to show it to the premium subscribers.
function kv_no_loginpage_access() { get_template_part( 'custom-login-page' ); exit(); }
That’s it. now you can prevent your visitor to access your site login page.