Switch URL element Tab with geolocate?
-
I have a webpage for contact info with tabs along the top for 4 different locations.
When you click on a different location the contact info on the pages change and the URL updates to add #horizontalTabX (where X is Tab 1-4 accordingly). I am trying to use the GeoIP detection lookup plugin through WP but I am pretty inexperienced with PHP and APIs…
For testing purposes, I’ve tried to tell it to switch to the AB Tab when it sees my location as BC (where I am testing from).
The main parts I feel like I am messing up are where it says if ($url = ‘/contact-us’;()) and the switch case to add the #horizontalTab2 onto the contact-us/ URL.
Any help is greatly appreciated. I am actively going through the documentation but I’m pretty lost.
add_action(‘template_redirect’, ‘geoip_redirect’, 5);
function geoip_redirect(){
if (is_admin())
return;// This condition prevents a redirect loop:
// Redirect only if the home page is called. Change this condition to the specific page or URL you need.
if ($url = ‘https://linestar.ca/contact-us/’;())
return;if (!function_exists(‘geoip_detect2_get_info_from_current_ip’))
return;$userInfo = geoip_detect2_get_info_from_current_ip();
$countryCode = $userInfo->mostSpecificSubdivision->isoCode;
switch ($countryCode) {
case ‘BC’:
$url = ‘contact-us/#horizontalTab2’;
break;
case ‘AB’:
$url = ‘contact-us/#horizontalTab2’;
break;
default:
$url = ”;
}
if ($url) {
wp_redirect(get_site_url(null, $url));
exit;
}
}The page I need help with: [log in to see the link]
- The topic ‘Switch URL element Tab with geolocate?’ is closed to new replies.