To change website content based on the visitor's country, look up the country from the visitor's IP address when the page is requested (your CDN can pass it as a header, or a personalization tool can do the lookup), map it to a small number of region groups, and swap a few page elements for each group on the same URL. Keep different languages on separate URLs with hreflang, never redirect automatically, and give everyone a visible way to switch region. That last part is what keeps the change safe for search and for the visitors your IP lookup gets wrong.
This how-to walks through each step for a B2B website: what to change by country and what deserves its own page, the three ways to detect the country, how to implement it (including on WordPress, where page caching is the usual trap), and how to test it.
Before You Start: What Google Says About Country-Based Content
Google's own guidance is cautious, and it is worth reading before you build anything. In its documentation on managing multi-regional and multilingual sites, Google says "Don't use IP analysis to adapt your content" and calls IP location analysis "difficult and generally not reliable". The same page says to avoid automatically redirecting users from one language version to another.
The reason is crawling. Google's page on locale-adaptive pages says the default IP addresses of Googlebot "appear to be based in the USA" and that the crawler sends requests without an Accept-Language header. If your page shows German visitors something US visitors never see, Google mostly sees the US version.
That does not mean you cannot personalize by country. It means two rules:
- Anything that should rank in a country gets its own URL. Language versions, country-specific product pages and local landing pages belong on separate URLs annotated with hreflang. Do not try to serve them from one URL by IP.
- Same-URL changes stay small and additive. A currency note, a compliance badge, a regional case study or a local office address can change by country on the same URL, as long as the default page is complete and useful to everyone, including Googlebot.
Step 1: Decide What Changes by Country
Most teams start with the wrong list. They want to translate the hero, change the pricing table and redirect to a local site. Sort every idea into one of two columns first.
| Change | Same URL, swapped by country | Separate URL with hreflang |
|---|---|---|
| Language of the page | Yes | |
| Currency shown next to prices | Yes, as a note or toggle default | If prices differ by market, yes |
| Compliance and data residency badges (for example GDPR, EU hosting, SOC 2) | Yes | |
| Customer logos and case studies from the region | Yes | |
| Phone number, office address, support hours | Yes | |
| Webinars and events in the visitor's time zone | Yes | |
| A country-specific offer or product that only exists in one market | Yes |
For a B2B site, the same-URL column is where the value is. Buyers in Europe look for where their data is stored; buyers in the US look for security attestations; buyers everywhere trust a customer from their own market more than a logo they do not recognise. Pick two or three of those changes, not all of them.
Step 2: Choose How to Detect the Country
There are three practical ways to get the visitor's country. The browser's location prompt is not one of them: asking a first-time B2B visitor for their location to show a different logo bar costs more trust than it earns.
| Method | How it works | Good for | Watch out for |
|---|---|---|---|
| CDN header | Your CDN adds the country to each request. Cloudflare, for example, sends a CF-IPCountry header with a two-letter country code, and uses XX when it has no country data and T1 for Tor traffic | Server-side and edge changes with no extra lookup | Only works if the site is behind that CDN; Cloudflare's docs list it under the "Add visitor location headers" Managed Transform |
| Server-side GeoIP lookup | Your server looks the IP up in a geolocation database on each request | Sites not behind a CDN that provides the country | The database needs regular updates; adds work to every request |
| Personalization tool (client-side) | A script resolves the visit and applies country rules in the browser | Marketing-owned changes on any CMS, combined with other rules such as industry | Needs a fast script and a flicker check |
Whichever you pick, expect some visits to resolve to the wrong country. Corporate VPNs and proxies often exit in the country of the company's headquarters, not the employee's. This is the main reason the change has to be small and the region switcher has to be visible.
Step 3: Map Countries to a Few Region Groups
Do not write rules per country. Write them per group, and keep the number of groups low enough that you can maintain the content. An illustrative mapping for a SaaS company selling into Europe and North America:
- EU and EEA: EU data hosting note, GDPR and DPA link, two European customer logos, prices shown in euros.
- United Kingdom: the same as EU, but with UK customer logos and prices in pounds.
- United States and Canada: security attestation badge, North American logos, US phone number.
- Everyone else, and unknown (
XX): the default page, which must work on its own.
Write the mapping down as a table the whole team can see. Most bugs in country personalization come from a country nobody assigned, such as Switzerland or Norway landing in the wrong group.
Step 4: Implement the Change
Option A: at the edge
If your site runs behind a CDN with workers, the worker can read the country and rewrite a marked element in the HTML before it reaches the browser. In Cloudflare Workers, the request object's cf.country property holds the two-letter code. This gives no flicker and works with any CMS, but it needs a developer and care with caching: the cached copy must not be the personalized one.
Option B: on the server
Read the country header or do the GeoIP lookup in your page template and render the right block. A simplified PHP example for a site behind Cloudflare:
$country = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? 'XX';
$eu = ['AT','BE','DE','DK','ES','FI','FR','IE','IT','NL','PL','SE'];
if (in_array($country, $eu, true)) {
get_template_part('partials/trust-eu');
} else {
get_template_part('partials/trust-default');
}
The list is shortened for the example; use the full set of countries in your group. The catch is page caching, covered in the WordPress section below.
Option C: with a personalization tool
A website personalization tool runs the lookup and applies the change in the browser, so marketing can edit the variants without a deploy. You create a segment such as "country is in the EU group", select the element in a visual editor, write the variant, and keep a holdout. The advantage over options A and B is that the country rule can be combined with others ("EU and healthcare", "US and target account") and measured per segment. In Markettailor, geography is one of the segmentation attributes next to industry, company size and behaviour, and the same rule can drive a test in A/B testing.
WordPress: Personalizing by Country Without Breaking the Cache
WordPress website personalization by country usually fails for one reason: page caching. Most WordPress sites serve a cached HTML copy from a caching plugin, the host or the CDN. If the first visitor after a cache clear is in Germany, everyone may get the German block until the cache expires.
There are three ways around it:
- Cache per country. Configure the cache to store one copy per country group (by varying on the country header). This works but multiplies cache entries, and not every host supports it.
- Exclude the page from caching. Simple, but it slows down exactly the pages you most want to convert, such as the homepage and pricing.
- Personalize in the browser. Keep the cached page identical for everyone and let a script swap the marked elements. This is how snippet-based personalization tools work on WordPress, and it avoids the cache problem entirely, at the cost of needing a fast script so the swap is not visible.
Whichever route you take, test with the cache warm, not right after a deploy. A country rule that works in a logged-in admin session (where caching is often off) can still be broken for real visitors.
Step 5: Build the Fallback and the Switcher
Two things protect you from the visits your detection gets wrong.
- A complete default. The default page is what Googlebot, unknown countries and VPN users see. Write it first and make sure it would convert on its own. Country content should add to it, never replace something essential.
- A visible region or language selector. Google recommends explicit links between versions rather than IP-based switching, and a buyer on a VPN needs a way out of the wrong version. Remember the choice in a cookie or local storage and let it override the IP-based rule.
Step 6: Test and Measure
- Check each group with a VPN set to a country in that group, plus one country that belongs to no group.
- Check what Google sees with the URL Inspection tool in Search Console. The rendered page should be your complete default.
- Check speed on a throttled mobile connection. If the swapped element flashes, move it lower on the page or move the change server-side.
- Measure against a holdout. Keep a share of each region group on the default page and compare demo or contact conversion between the two. Country groups are often small in B2B, so expect to wait weeks for a result; our A/B test calculator shows how long.
A Worked Example
An illustrative example. A B2B software company with customers in the US and Europe sees that European demo requests often ask about data hosting in the first call. It adds one country rule to the homepage and pricing page:
- EU and EEA visitors: a line under the pricing table, "Hosted in the EU (Frankfurt). Data processing agreement available", and two European customer logos in the logo bar.
- US visitors: the security attestation badge moves next to the call to action.
- Everyone else: the default page, which mentions both hosting regions lower down.
Nothing is translated, nothing is redirected, and the URL stays the same. The team keeps 20% of each group on the default page and compares demo request rates after six weeks. If you want the same approach for other attributes, our guides cover personalizing by industry and personalizing by company size.
Common Mistakes
- Auto-redirecting by IP to a country or language site. It traps VPN users and hides versions from crawlers.
- Translating on the same URL by IP. Languages need their own URLs and hreflang.
- Too many groups. Twelve country variants of a logo bar will not all be kept up to date.
- Testing only while logged in to WordPress, where caching is off.
- Forgetting the privacy notice. Say in plain words that you adapt content by region. Our post on B2B personalization and data privacy covers what else to disclose.
Frequently Asked Questions
How do I change website content based on the visitor's country?
Get the country from the visitor's IP address, either from a CDN header such as Cloudflare's CF-IPCountry, a server-side GeoIP lookup or a personalization tool, then show a different version of a few page elements for each region group on the same URL. Keep a complete default for unknown visitors and a visible region selector.
Does changing content by country hurt SEO?
It can, if important content is only visible to some countries. Google mostly crawls from US IP addresses and recommends separate URLs with hreflang for language and country versions. Small, additive changes on the same URL, such as a currency note or regional logos, are low risk as long as the default page is complete.
How do I personalize a WordPress website by country?
Either render country blocks in the theme from a CDN country header (and configure the cache to vary by country), exclude the page from caching, or use a script-based personalization tool that swaps elements in the browser so the cached page stays the same for everyone. The browser approach avoids the caching problem.
How accurate is detecting a visitor's country from their IP address?
Accurate enough for small changes, not for anything a visitor cannot undo. Google describes IP location analysis as "generally not reliable" for adapting content, and corporate VPNs and proxies can place a visitor in the wrong country. That is why the region selector and the complete default page matter.
Should I redirect visitors to a country site automatically?
No. Google's guidance is to avoid automatically redirecting users from one language version to another and not to use IP analysis to adapt content. Suggest the local version with a banner or link instead, and remember the visitor's choice.