function restrict_login_page_by_country_idc() { if (strpos($_SERVER['REQUEST_URI'], '/wp-login.php') !== false) { if (!country_specific_idc()) { wp_redirect('https://yoursite.com/'); exit; } } } add_action('init', 'restrict_login_page_by_country_idc'); function country_specific_idc() { $ip_address = $_SERVER['REMOTE_ADDR']; $url = "https://ipapi.co/{$ip_address}/country/"; $response = wp_remote_get($url); if (!is_wp_error($response)) { $body = wp_remote_retrieve_body($response); if (strtolower(trim($body)) === 'us') { return true; } } return false; }