How To Redirect Users Based On Geolocation On WordPress

Looking for a way to redirect users based on geolocation on your WordPress site?

This functionality has a ton of different use cases. Based on a user’s geolocation, you can send people to:

  • A landing page that’s dedicated to their location.
  • Their local language if you run a multilingual WordPress site.
  • A completely separate domain.
  • Anything else that meets your needs!

But in its default state, WordPress doesn’t include any geo-redirect functionality, which means that you’ll need to turn to some third-party geotargeting solutions.

In this post, you’ll learn how you can redirect users based on geolocation without writing a single line of code. We’ll cover two different types of redirects:

  • Static – you redirect all users from a certain geolocation to a single, static URL.
  • Dynamic – you redirect users to certain pages based on the initial page that they visited. This is especially helpful for language redirects because you can send users to the exact same content on the version of your site in a different language.

Keep reading for an easy step-by-step guide that anyone can follow!

What You Need To Redirect Users Based On Geolocation On WordPress

For this tutorial, you’ll need the Geo Redirects plugin from Geotargeting WP. This plugin is free to download and includes a 14-day free trial, so you can follow this tutorial 100% for free.

To get started, download the plugin and create a Geotargeting WP account. Once you install and activate the plugin, add your website to the Allowed domains area in the Api Keys part of your Geotargeting WP dashboard:

redirect-based-on-geolocation-wordpress-1

Then, go to GeotargetingWP → Settings in your WordPress dashboard and add your API keys to the plugin’s settings to finish the basic configuration:

redirect-based-on-geolocation-wordpress-2

Now, you’re ready to start redirecting users based on their location!

How To Set Up A Static Redirect Based On A User’s Geolocation

For this first tutorial, we’ll show you how to redirect users to a single static page based on their geolocation.

Step 1: Create A New Geo-Redirect

To create your first geo-redirect, go to GeoTargetingWP → Geo Redirects in your WordPress dashboard. Then, click Add New:

redirect-based-on-geolocation-wordpress-3

Step 2: Choose Conditions To Trigger Redirect

Next, you’ll use a combination of Redirection Rules to configure exactly which users should be redirected (and when).

For example, if you want to target users in Germany, you would make the rule Country…is equal to…Germany:

redirect-based-on-geolocation-wordpress-4

These rules let you get pretty creative with how your redirects function because you can add multiple rules to the same redirect. You can also use both AND conditions and OR conditions:

  • AND groups – all the conditions must be met in order for the redirect to fire.
  • OR groups – as long as one OR group’s conditions are met, the redirect will fire.

For example, let’s say that you want to redirect users who:

  • Are located in Germany
  • AND are not logged into WordPress

You can set up an AND group like so:

redirect-based-on-geolocation-wordpress-5

In total, you can use rule conditions like:

  • Country, USA state, City
  • Posts, pages, categories, tags, etc.
  • User status, e.g. logged in, user role, etc.
  • Referrer
  • Device, e.g. desktop, tablet, phone
  • Query parameter

And you can also just target specific URLs if needed.

Step 3: Enter Destination URL

Once you’re finished configuring your redirect rules, scroll down to the Redirection Options to finish configuring your redirect.

Enter the page that you want to redirect visitors to in the Destination URL box. Remember, for this tutorial we’re just focused on a static URL, so all you need to do is paste in the direct URL. In the next section, we’ll talk about some of the things that those placeholders let you do:

redirect-based-on-geolocation-wordpress-6

Step 4: Configure Other Basic Redirect Settings

Under the Destination URL box, you can configure some other basic settings for your redirect:

  • One-time redirect – choose how often the visitor should be redirected. You can redirect every single visit, only one visit, or only one time per session.

 

  • Exclude search engines – you can exclude crawler bots like Google from being redirected.
  • Pass query string – this lets you pass query strings, like UTM tracking.
  • Redirection code – by default, the plugin uses 302 temporary redirects. But you can enter a different redirect code if desired.
  • IP Whitelist – this lets you exclude specific users from being redirected.

Once you’re done, click Publish to make your redirect live.

How To Set Up A Dynamic Redirect Based On A User’s Geolocation

With a dynamic redirect, you’re able to use placeholder variables to send users to different pages based on their location or the page that they try to visit.

These are especially helpful when you want to send users to a different translation of your site while still serving up the same content. Or, you could use them to create separate landing pages for different countries (or anything else!)

The main setup process is the same as the previous tutorial – the only difference is the Destination URL option. If you look below the field, you’ll see a list of potential variables:

redirect-based-on-geolocation-wordpress-8

These are what you use to create your dynamic redirect.

An Example Of Dynamically Redirecting Users Based On Location

Let’s say you have three versions of your site. The main version is English. Then, you also have German and Argentinean translations on a subdomain:

  • yoursite.com – main site.
  • de.yoursite.com – German translation.
  • ar.yoursite.com – Argentinian translation.

You want to be able to dynamically redirect users so that if a German visitor comes to yoursite.com/example-post, they get redirected to de.yoursite.com/example-post. Likewise, an Argentinean visitor gets sent to ar.yoursite.com/example-post.

Dynamic redirects let you do that with a single set of redirect rules.

You would use the Redirection rules to target people from either Germany OR Argentina.

Then, you could use the dynamic placeholders to set up your Destination URL like this:

This tells the plugin to automatically:

  1. Insert the two-letter country code as the subdomain (this handles sending visitors to the proper translation).
  2. Append the URL path that the visitor is trying to access (this ensures they see the same content – just in a different language).

And that’s all there is to it. Using a single redirect rule, you’ll be able to dynamically send people to the proper language no matter how many different languages your site supports.

Start Redirecting Users Based On Their Location Today

Whether you want to use visitors’ locations to redirect them to a single static page or dynamically redirect them based on the content they’re looking at, you now know everything you need to get started.

Do you have any other questions about using geo-redirects on WordPress? Leave a comment!

About the Author

Susmita is an engineer, a writer and a dancer - not necessarily in that order ! Ever since she discovered WordPress, she has not ceased to be amazed by how this community-driven platform brings people together - in more ways than one. And yes, she loves binge-watching movies !

Leave a Reply

Your email address will not be published. Required fields are marked *