PIT Designs Logo

How to Lock Entire WordPress Website for the Public Without Plugins

I'm the owner and founder of PIT Designs. I love creating digital presence and creative digital solutions for our clients.


Posted 4 years ago on February 12th, 2023.

Related To:

Tags:
How To Create Effective Ads for Home Services Marketing

Advertising for home services, such as lawn care, home cleaning, and garden maintenance, isn’t as simple as tossing up an […]

How applicant tracking systems are revolutionizing remote recruitment

Gone are the days of traditional recruitment. Applicant tracking systems have been revolutionizing how we hire, and their impact is here to stay. But how is the change happening? Tap to learn more about it.

Check out the New AI Features in FlexClip 5.0

In today's digital era, the importance of video content cannot be overstated. Videos have become an integral part of various […]

Effective Cleaning Tips for Maintaining a Clean and Healthy Home

We’ll explore some practical tips and tricks that will help you establish an effective cleaning routine. You might not realize […]

The Art of Visual Storytelling

How to use visual elements to tell a story Let's start with an interesting fact that will amaze you. Do […]

The Ultimate Guide to Choosing a Great Domain Name for Your Business

Choosing the right domain name for your business is a critical step in building a strong online presence. Your domain […]

6 Mistakes to Avoid When Creating a React-Native App

React Native is a leading cross-platform app development framework that has more than one and half thousand active contributors. The […]

Will Elon Musk Turn Twitter into a Super-App?

Elon Musk envisions a future where mobile apps are consolidated into one-stop shops within a single platform. Will he create a "super app" to rule them all in 2023? Learn about the challenges he faces and the potential impact on companies like Twitter and Apple's App Store.

You can lock your entire WordPress website and make it only visible to logged-in users without using a plugin by adding code to your WordPress theme's functions.php file. Here's how you can do it:

Step One: Access functions.php

Access the functions.php file: Go to your WordPress dashboard, navigate to "Appearance" -> "Editor" and select the "functions.php" file.

Step Two: Add the Code

Add the following code to the functions.php file:

function private_site() {
if (!is_user_logged_in()) {
wp_redirect(wp_login_url());
exit;
}
}
add_action('template_redirect', 'private_site');

Step Three: Save & Test

Save the changes: After adding the code, click the "Update File" button to save the changes.

Test it: Log out of your WordPress website and try accessing a page on your website. You should be redirected to the login form.

That's it!

Your entire WordPress website is now only visible to logged-in users.

This code will redirect any non-logged-in user to the login form whenever they try to access any page on your website.

menu-circlecross-circle