How To Force Users To Login Before Viewing Your WordPress

Do you wanna restrict your WordPress website just to some clients or registered users? You can easily force users to login before viewing your WordPress.

We can use auth_redirect() function to checks if user is logged in, if not it redirects them to login page. Upon logging in, they will be sent redirected to the page where they originally landed.

To restrict access to the your WordPress, drop the following into your current theme’s functions.php file:

That’s it! This will keep unwanted audience away. This snippet comes straight from the Force Login plugin, and if you like this plugin/snippet then please consider donating some money to the author of the plugin. :)