For under construction or admin only sites:
functions.php
function custom_restrict_entire_site() {
// 1. Check if the user is NOT logged in
// 2. Ensure we aren't blocking the login page itself (to avoid infinite loops)
if ( ! is_user_logged_in() && ! is_login() ) {
// Set a 403 Forbidden HTTP status code for security/SEO best practices
status_header( 403 );
// Output the blank page style and your message
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Please Login</title>
<style>
body {
background-color: #ffffff; /* Turns the website blank/white */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
color: #333333;
font-size: 1.2rem;
}
a {
color: #0073aa;
text-decoration: none;
font-weight: bold;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div>
- Please <a href="<?php echo esc_url( wp_login_url() ); ?>">login</a>
</div>
</body>
</html>
<?php
// Stop WordPress from loading the rest of the website
exit;
}
}
add_action( 'template_redirect', 'custom_restrict_entire_site' );