Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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