Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created January 29, 2018 16:54
Show Gist options
  • Save Garconis/02b65a0acae7f4bc7ac0c3e33b7ffbe5 to your computer and use it in GitHub Desktop.
Save Garconis/02b65a0acae7f4bc7ac0c3e33b7ffbe5 to your computer and use it in GitHub Desktop.
WordPress | Redirect pages to the homepage, if the user isn't logged in. Good for maintenance mode.
<?php
// if it's not the homepage and they aren't logged in, redirect to the home URL
add_action( 'template_redirect', 'fs_maintance_mode' );
function fs_maintance_mode() {
if ( !is_home() && !is_user_logged_in() ) {
wp_redirect( esc_url_raw( home_url() ) );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment