How-to 5 min read

How to determine the user's city on the site

For commercial projects that offer different conditions of service depending on the region of the client, you need to implement the choice of the city on the site. The location of the user is determined by geolocation or check IP-address.

Why do you need to determine the location of the user

Adding the function of city selection to the site is needed on multiregional resources that provide different content depending on location:
Selecting city in the online store
Geolocation marketing is important for commercial sites that may have different service lists, prices and shipping costs depending on the region. Also, the user's location is necessary for information portals that provide a directory of local organizations and enterprises.

After selecting a city, the content change is implemented differently. On some sites, changing only the local phone numbers in the header, and on the other — the regional subdomain loaded by changing the city.

Such filtering helps to display not only the data for the entire region, but also to customize the content to a more precise location — the city area right up to the user's home, showing certain places nearby: for example, the store or office nearest to the customer.
Information about the location is provided only with the consent of the user, so you must first ask him to allow to determine geolocation.
How do websites determine location? If the user does not allow geolocation to be enabled in his browser, you need to determine the city by the visitor's IP address or display universal content without regional linkage. Checking the IP address may be inaccurate, so do not rely on it completely.
City auto-detection on the site
To implement the choice of the city on the site, you can use js-scripts, modules for the used CMS, API geolocation Google. Using the geolocation API will require programming skills: you need to configure error handling, set the location information update intervals, and if necessary, override the accuracy of the geolocation.

Google recommends you do not request information about the location of the visitor immediately upon loading, as the majority of users in such a situation will deny access to this data. You also need to explain exactly what location information is for.

How to add a city selection to a WordPress site

To set a visitor's location on WordPress, you can use the "Multi-City AV":
WordPress visitor location plugin
The plugin allows you to add shortcodes that give an opportunity to customize different content display depending on the client's location. When choosing a location, the base of cities is used.

The developer's site contains code snippets that must be added to the website to use this functionality.

To correctly configure the choice of the city on the website, you need knowledge in the field of web development. If not, you can get help from the developers.
select city in Multi-City AV plugin
The region is automatically determined from the list, and you can manually select another city. The system determines the latitude and longitude of the user's location, sets the country, region and city.

How to add a city choice to the OpenCart website

You can implement this functionality using the module "[OLD] Geo IP Tools".
IP city definition module for OpenCart
The tool is compatible with any version of OpenCart and performs the following functions:

  • allows you to determine the location by IP-address, also giving the opportunity to select the city manually;
  • when placing an order, information about the country and city is filled in automatically;
  • for different cities you can display different content;
  • You can set up a redirect, depending on the client's city, to the corresponding subdomain or URL;
  • there are bases with cities.

Example of the module:
geolocation module for OpenCart


Defining the client's city allows you to change the content of the site depending on the location of the user. At the same time, you can either replace individual elements, such as a phone number and address, or load a regional subdomain with completely changed information and design.

To implement the functionality manually, you need web development skills or specialist assistance. You can also find ready-made solutions for your CMS, which are easy to customize yourself.

This article is a part of Serpstat's Checklist tool
Checklist at Serpstat" title = "How to determine the users' city on the site 16261788318376" />
Checklist is a ready-to-do list that helps to keep reporting of the work progress on a specific project. The tool contains templates with an extensive list of project development parameters where you can also add your own items and plans.
Try Checklist now

Speed up your search marketing growth with Serpstat!

Keyword and backlink opportunities, competitors' online strategy, daily rankings and SEO-related issues.

A pack of tools for reducing your time on SEO tasks.

Get free 7-day trial

Rate the article on a five-point scale

The article has already been rated by 1 people on average 3 out of 5
Found an error? Select it and press Ctrl + Enter to tell us

Share this article with your friends

Are you sure?

Introducing Serpstat

Find out about the main features of the service in a convenient way for you!

Please send a request, and our specialist will offer you education options: a personal demonstration, a trial period, or materials for self-study and increasing expertise — everything for a comfortable start to work with Serpstat.




We are glad of your comment
I agree to Serpstat`s Privacy Policy.

Thank you, we have saved your new mailing settings.

Report a bug

Open support chat
mail pocket flipboard Messenger telegramm