S
S
squirtazzer2018-02-16 03:00:51
WordPress
squirtazzer, 2018-02-16 03:00:51

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

1 answer(s)
D
Denis Yanchevsky, 2018-02-16
@deniscopro

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' );

For St. Petersburg site
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 question

Ask a Question

731 491 924 answers to any question