Last active
September 20, 2020 10:36
-
-
Save ohid/9e741fc80c167901b34e580d93826401 to your computer and use it in GitHub Desktop.
The code will redirect visitors from desktop devices but not for a specific user. Change the $my_ip to your own IP.
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 characters
<?php | |
// Redirect mobile visitors to your desktop site | |
function wimtec_mobile_redirect() { | |
// My IP | |
$my_ip = '90.22.192.117'; | |
// Get the client IP | |
$client_ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']); | |
if( $client_ip === $my_ip ) { | |
return false; exit; | |
} else { | |
if( ! wp_is_mobile() ) { | |
wp_redirect('https://wimtec.net'); | |
exit; | |
} | |
} | |
} | |
add_action('init', 'wimtec_mobile_redirect'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment