Published on Jun 13, 2021

How to Get Visitor Country in WordPress

Sridhar Katakam

This members-only tutorial provides the steps for showing the visitor's country on the frontend in WordPress.

Caveat: This may not work reliably when your pages are cached, especially on the server-side. You are advised to test this thoroughly before using it in production.

Step 1 - Get IP Address

Let us register a custom function to get the IP address of the visitor.

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Function] Get IP Address

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-down