Implementing redirect feature on individual wordpress page
-
Hi Benjamin,
I am trying to implement this feature “Redirect depending on country” mentioned in the following page.
What I did was as follows:
1) Create a custompaget1.php script as shown below.
2) This script would reside in my public_html/wp-content/themes/directory2-child
3) Create a new page in wordpress using the above scriptHowever, the redirecting does not seem to work. I get a blank page when I load up the page. My aim is to create redirects for particular pages within wordpress.
Thank you.
<?php /* Template Name: CustomPageT1 */ ?> <?php 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 (!is_home()) return; if (!function_exists('geoip_detect2_get_info_from_current_ip')) return; $userInfo = geoip_detect2_get_info_from_current_ip(); $countryCode = $userInfo->country->isoCode; switch ($countryCode) { case 'DE': $url = '/germany'; break; case 'US': $url = '/usa'; break; case 'SG': $url = 'www.google.com'; break; default: $url = 'www.google.com'; } if ($url) { wp_redirect(get_site_url(null, $url)); exit; } } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Implementing redirect feature on individual wordpress page’ is closed to new replies.