Restrict WordPress login access by hiding wp-login

WordPress websites are having more prone to suffer attacks and hacks. Because everyone knows the path of dashboard and structure of wp site. Many WordPress websites are just operated by 1-2 users and a normal user doesn’t need to have an account to visit website.

Furthermore dashboards are accessed less frequent for static websites. We can secure these sites through restrict WordPress login access by hiding wp-login and it requires only a few line of code. Write the code below in your theme’s functions.php file:

Restrict WordPress login access by hiding wp-login

We are using wp $pagenow global variable and a local variable called $restrict_login which is either true (1) or false (0). If it’s set to true, anyone who will try to access wp-login.php will be redirected to home page. To allow login, you must set $restrict_login variable’s value to 1.

In this way you can hide login file from website visitors and everyone else. You can also try WordPress security and limit login access plugins if your requirements are broad.

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.