admin管理员组文章数量:1391975
I want to redirect WordPress pages as per location e.g domainname/ar, domainname/fr etc, but the code goes into an infinity loop.
Here is the snippest:
function redirect_location(){
//$UserDetailss = var_export(unserialize(file_get_contents('.gp?ip=')));
$UserDetails = unserialize(file_get_contents('.gp?ip='));
$userCountry = $UserDetails['geoplugin_countryCode'];
if($userCountry == 'AR'){
$url = home_url('/ar/');
} else if($userCountry == 'FR'){
$url = home_url('/fr/');
} else {
$url = home_url('/in/');
}
if (is_page() || is_home()) {
wp_redirect($url);
exit;
}
}
add_action('template_redirect', 'redirect_location');
I want to redirect WordPress pages as per location e.g domainname/ar, domainname/fr etc, but the code goes into an infinity loop.
Here is the snippest:
function redirect_location(){
//$UserDetailss = var_export(unserialize(file_get_contents('http://www.geoplugin/php.gp?ip=')));
$UserDetails = unserialize(file_get_contents('http://www.geoplugin/php.gp?ip='));
$userCountry = $UserDetails['geoplugin_countryCode'];
if($userCountry == 'AR'){
$url = home_url('/ar/');
} else if($userCountry == 'FR'){
$url = home_url('/fr/');
} else {
$url = home_url('/in/');
}
if (is_page() || is_home()) {
wp_redirect($url);
exit;
}
}
add_action('template_redirect', 'redirect_location');
Share
Improve this question
edited Feb 20, 2020 at 9:57
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked Feb 20, 2020 at 7:32
ShadowShadow
685 bronze badges
1 Answer
Reset to default 2Us this code instead:
function redirect_location(){
global $wp;
$current_url = home_url( $wp->request );
$UserDetails = unserialize(file_get_contents( 'http://www.geoplugin/php.gp?ip=' ) );
$userCountry = $UserDetails['geoplugin_countryCode'];
if($userCountry == 'AR'){
$url = home_url('/ar/');
} else if($userCountry == 'FR'){
$url = home_url('/fr/');
} else {
$url = home_url('/in/');
}
if( ( is_page() || is_home() ) && ( strpos( $current_url, $url ) === false ) ) {
wp_redirect($url);
exit;
}
}
add_action('template_redirect', 'redirect_location');
本文标签: page templatewpredirect goes to infinity loop
版权声明:本文标题:page template - wp_redirect goes to infinity loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744731572a2622076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论