Support » Plugin: WP Engine GeoTarget » Redirect on first visit

Viewing 1 replies (of 1 total)
  • Thread Starter toimisto

    (@toimisto)

    This is where I am but this still doesnt work. Any idea how to fix this?

    function wpe_country_redirect() {
    
    if( is_home() || is_front_page() ) {
    
    $cookie_name = "country";
    
    $country = null;
    
    if ( class_exists( 'WPEngine\GeoIp' ) ) {
    $geo = WPEngine\GeoIp::instance();
    $country = $geo->country();
    }
    
    if (!isset( $_COOKIE[$cookie_name] )
        // do nothing
    ) {
    
    setcookie('country', $country, time() + (3600 * 24 * 30), '/');
    
    // Create redirect rules based on country codes
      switch($country){
    
        case 'FI':
        wp_redirect( 'https://url.com/fi', 301 ); exit;
    
        case 'DE':
        wp_redirect( 'https://url.com/de', 301 ); exit;
    
        default:
        break;
      }
    }
    }
    }
    add_action( 'init', 'wpe_country_redirect' );
    • This reply was modified 2 years ago by toimisto.
Viewing 1 replies (of 1 total)
  • The topic ‘Redirect on first visit’ is closed to new replies.