Skip to content

Instantly share code, notes, and snippets.

@seferdemirci
Created February 26, 2022 14:19
Show Gist options
  • Save seferdemirci/588f89185cfb00db7114ed9629c47680 to your computer and use it in GitHub Desktop.
Save seferdemirci/588f89185cfb00db7114ed9629c47680 to your computer and use it in GitHub Desktop.
This bunch of code is for to hide WordPress Login Page
<?php
// Add rewrite rule to use custom path for accessing the wp-login.php file
function redirect_custom_login(){
add_rewrite_rule('custom-login', 'wp-login.php', 'top');
}
add_action('init', 'redirect_custom_login');
// Redirect if user come from 'custom-login' url
function redirect_to_home_page(){
$newLogin = 'custom-login';
if (explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))[1] !== $newLogin) {
wp_safe_redirect(home_url(), 302);
exit();
}else{
if(is_user_logged_in()){
wp_safe_redirect(admin_url(), 302);
exit();
}
}
}
add_action('login_head', 'redirect_to_home_page');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment