Created
April 16, 2021 11:28
-
-
Save acerus/1affa73c4494287ceaec9f9d6540a312 to your computer and use it in GitHub Desktop.
Auto redirect to different URLs based on mobile devices, WordPress
This file contains 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
// Adds app redirect rules | |
add_action( 'wp_head', 'download' ); | |
function download() { ?> | |
<script type="text/javascript"> | |
// redirect for iPhone / iPad: | |
if (( navigator.userAgent.match( /iPhone|iPad|iPod/i ) )) { | |
document.location.href = 'https://iphone.com'; | |
} | |
// redirect to Samsung Galaxy Store: | |
if (navigator.userAgent.match( /SAMSUNG|SGH-[I|N|T]|GT-[I|P|N]|SM-[N|P|T|Z|G]|SHV-E|SCH-[I|J|R|S]|SPH-L/i )) { | |
document.location.href = 'https://galaxy.com'; | |
} | |
//redirect for Android: | |
else if (navigator.userAgent.match( /Android/i )) { | |
document.location.href = "https://android.com"; | |
} | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment