Skip to content

Instantly share code, notes, and snippets.

@timersys
Last active May 2, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timersys/31309f9ff41d64ea412e to your computer and use it in GitHub Desktop.
Save timersys/31309f9ff41d64ea412e to your computer and use it in GitHub Desktop.
Geotargeting redirects
<?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