Skip to content

Instantly share code, notes, and snippets.

@rodelrod
Forked from timersys/geot-redirects.php
Created October 15, 2016 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodelrod/ed1cd3d2edf5c2f0ee7b04c87b2b795c to your computer and use it in GitHub Desktop.
Save rodelrod/ed1cd3d2edf5c2f0ee7b04c87b2b795c to your computer and use it in GitHub Desktop.
Geotargeting redirects
<?php
/**
* 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( 'init', 'geot_custom_redirects');
function geot_custom_redirects() {
global $geot;
// if main plugin is not enabled return
if( ! function_exists( 'geot_target' ) )
return;
// if search engine exit
if( $geot->functions->isSearchEngine() )
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