Just wanted some advice in relation to adding some custom code to my wordpress site. I am using geoip
to check a users country code and redirect them to the relevant site when they land on my homepage.
Currently I include this block of php
code at the very top of my themes header.php
file. However I'm not sure that is the best way to go about it, would it be better off in the functions.php
and if so is there a hook
I can use to call this code when the homepage is about to be loaded and redirect accordingly?
$url = $_SERVER['REQUEST_URI'];
require_once("geoip.inc");
$gi = geoip_open(dirname(__FILE__) . "/GeoIP.dat", GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
if ($url === "/") {
//If IE go to /ie
if ($country_code === "IE") {
header("Location: http://www.wpmultisite.com/ie");
die();
}//If GB go to /uk
else if ($country_code === "GB") {
header("Location: http://www.wpmultisite.com/uk");
die();
}
}
I should point out I'm trying to set up a network of sites using the Wordpress Multisite
functionality.
Many thanks in advance for any of your help.