• Pricing
  • Help
  • My Account
  • Download
WP Ghost
  • Pricing
  • Help
  • My Account
  • Download

Redirect Visitors To Login (Force Login Page)

/Developers /Hooks /Redirect Visitors To Login (Force Login Page)

If you want to create a login-based website and need to redirect all your visitors to the login page, add this code to your theme’s functions.php file.

function protect_whole_site() {
   if (!is_user_logged_in()) {
     if (isset($_SERVER['REQUEST_URI'])) {
        $url = untrailingslashit($_SERVER['REQUEST_URI']);
        if (strpos($url, HMWP_Classes_Tools::getOption('hmwp_login_url')) === false) {
           wp_redirect(site_url('wp-login.php'));
           exit();
        }
    } else {
        wp_redirect(site_url());
        exit();
    }
  }
}
add_action('template_redirect', 'protect_whole_site');

If you have Ghost mode activated in WP Ghost, the redirect will made to the new login path.

Tagged: login redirectvisitors redirect

Related Articles

  • Stop Plugin Auto Update Check

  • Adding a Custom CMS Simulator

  • WP Ghost Constants in wp-config.php

  • Change Paths in Admin Dashboard

  • Add Files to “Hide WordPress Common Files”

  • Change or Remove Login Logo Link

WP Ghost - Best Practice

Learn how to set up WP Ghost in Ghost Mode and activate all the security features you need for a stronger and safer website.

Most Popular

  • Change and Hide wp-admin Path with WP Ghost
  • Setup WP Ghost on Nginx Server
  • WP Ghost Compatibility Plugins List
  • Set AllowOverride all on Apache Servers
  • Theme Not Loading Correctly and Website Loads Slower
  • Lesson 3 – Hide Your Site From Theme Detectors and Hackers Bots
  • Change admin-ajax.php Path with WP Ghost
  • Firewall and Security
  • Lesson 1 – Customize Paths with WP Ghost
  • How To Change File Permissions in WordPress
  • Change plugins Path with WP Ghost
  • Brute Force Attack Protection
  • WP Ghost Settings – Best Practice
  • Change REST API Path with WP Ghost
  • Change and Hide wp-login Path with WP Ghost
  • Change wp-content Path with WP Ghost
  • Redirects
  • Two-Factor Authentication
  • Brute Force Protection in Elementor Login Forms
  • What is WP Ghost?
  • Disable Right-Click and Keys
  • Change wp-register Path with WP Ghost
  • WP Ghost Compatibility Themes List
  • Install WP Ghost Lite Plugin
  • Hide wp-admin And wp-login.php From Source Code
  • Change author Path and Hide ID with WP Ghost
  • Events Log Report
  • Temporary Logins
  • WP Ghost – Advanced Pack
  • Setup WP Ghost on Nginx Web Server With Virtual Private Server

Recommended

  • What is WP Ghost?
  • Changelog
  • Plugin Best Practice
  • Plugin Compatibility
  • Theme Compatibility

Categories

  • Change Paths
  • Firewall
  • Temporary Login
  • Two Factor
  • Brute Force
  • Events Log

Company

  • Affiliate
  • Media Kit
  • Terms Of Use
  • Privacy Policy
  • Contact

Useful

  • Hack Attack Types
  • Key Security Features
  • Security Features
  • Free vs PRO
  • Why WP Ghost
  • Pricing
  • Facebook
  • YouTube
  • X
© WP Ghost 2016-2025