PHP Geotarget redirect not working in wordpress site

  geotargetting, php, wordpress

I have GeoTarget by WPengine installed on the server and the plugin installed. Per their docs, I need to set the redirect up in PHP and place in /mu-plugins folder.

This is the code I have in the geoip.php file:

<?php

/*
Plugin Name: GeoTarget Redirect
Description: Redirecting visitor traffic based on geo-location using the WPEngine GeoTarget feature
Version: 1.2
License: GPLv2
*/

function country_geo_redirect() {
$country = getenv('HTTP_GEOIP_COUNTRY_CODE');
if ( $country == 'PH' ) {
wp_redirect( 'https://siteph.com', 301 );
     exit;
} 
}
add_action('init', 'country_geo_redirect');

When I add it to the /mu-plugins folder, the site breaks. Not sure what I’m doing wrong and WPengine can’t help with the PHP code :

Btw, we’ve tried website level plugin solutions and had unreliable results. Hence why we’re using this solution.

Source: Ask PHP

LEAVE A COMMENT