Answer the question
In order to leave comments, you need to log in
How to make a redirect to another site if Peter's ip?
Good afternoon. There are two sites in St. Petersburg and Khabarovsk. Is it possible to do something so that when entering from St. Petersburg ip, the site redirects to the St. Petersburg site, when entering from Khabarovsk, respectively, to the Hub? Or some other way to do it? Maybe a stub and a person chooses himself? Is there such a plugin for wp? Thank you
Answer the question
In order to leave comments, you need to log in
Kind.
1. Install the GeoIP Detection plugin on both sites .
2. Then add something like this code:
For a site in Khabarovsk
function my_page_template_redirect(){
$city = do_shortcode( '[geoip_detect2 property="city.name" lang="ru"]' );
if( $city == 'Санкт-Петербург' ){
wp_redirect( 'http://spb.ru' ) );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
function my_page_template_redirect(){
$city = do_shortcode( '[geoip_detect2 property="city.name" lang="ru"]' );
if( $city == 'Хабаровск' ){
wp_redirect( 'http://khv.ru' ) );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question