Last active
May 2, 2017 13:19
-
-
Save timersys/31309f9ff41d64ea412e to your computer and use it in GitHub Desktop.
Geotargeting redirects
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
<?php | |
use Jaybizzle\CrawlerDetect\CrawlerDetect; | |
/** | |
* Create Custom Redirects from home page only | |
* @link http://wp.timersys.com/geotargeting/ | |
* | |
* @wordpress-plugin | |
* Plugin Name: GeoTargeting Pro Custom Redirects | |
* Plugin URI: http://wp.timersys.com/geotargeting/ | |
* Description: Geo Targeting custom redirects | |
* Version: 1.0.0 | |
* Author: Timersys | |
* Author URI: http://wp.timersys.com/geotargeting/ | |
*/ | |
add_action( 'template_redirect', 'geot_custom_redirects'); | |
function geot_custom_redirects() { | |
// if main plugin is not enabled return | |
if( ! function_exists( 'geot_target' ) ) | |
return; | |
// check for crawlers | |
$CD = new CrawlerDetect(); | |
if( $CD->isCrawler() ) | |
return; | |
// if is admin user or backend return | |
//if( is_admin() ) | |
// return; | |
// if not in home page return | |
if( ! is_front_page() ) | |
return; | |
if( geot_target( 'US' ) ) { | |
wp_redirect( 'http://domain.com/us-home-page' ); | |
die(); | |
} | |
if( geot_target('', 'Other Region name you created' ) ) { | |
wp_redirect( 'http://domain.com/ca-home-page' ); | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment