Created
May 17, 2024 09:06
-
-
Save adczk/5d29a5e05112505850fc8f4f8b51b74b to your computer and use it in GitHub Desktop.
Revisions
-
adczk created this gist
May 17, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ <?php // redirect front-end add_action( 'template_redirect', 'redirect_guests_home' ); function redirect_guests_home() { if ( !is_user_logged_in() ) { $homepage_id = get_option('page_on_front'); if ( ! is_page( $homepage_id ) ) { wp_redirect( get_home_url() ); } } } // redirect wp-admin and wp-login.php add_action('init','redirect_guest_login_home'); function redirect_guest_login_home(){ if ( !is_user_logged_in() ) { $page_viewed = basename($_SERVER['REQUEST_URI']); if ( $page_viewed == "wp-login.php" OR ( strpos( $page_viewed, "wp-admin") !== false ) ) { wp_redirect( get_home_url() ); exit(); } } }