Skip to content

Instantly share code, notes, and snippets.

@ohid
Last active September 20, 2020 10:36
Show Gist options
  • Save ohid/9e741fc80c167901b34e580d93826401 to your computer and use it in GitHub Desktop.
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.
<?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