How to Get the IP Address and Location of Users in WordPress

Struggling to get the IP address and location of your website visitors on WordPress? I know you must have gone through a lot of guides that only tell you how to fetch the IP address, but leave out how to find the location and exact Geo Coordinates of the user.

Your search finally ends here. Understanding the needs of webmasters like yourself, I’ve developed a WordPress plugin called “User IP and Location.” It’s a super useful tool for capturing not just the IP but also the location details, Geo Coordinates, and much more whenever someone visits your site.

If you’re unsure about how to get hold of the visitor’s IP and location details, just stick with me. Read this guide thoroughly to learn all about it.

How to Get User IP and Location in WordPress

Here are the steps through which you can get the user IP, location, and other details using the WordPress plugin named “User IP and Location” which is available for free on the WordPress repository.

get user ip and location, getting user ip in wordpress, getting user location in wordpress, user ip and location
Plugin Named “User IP and Location”

To set up this plugin, you can either get the plugin files from the WordPress store or log in to your WordPress admin panel. After you log in, just go to “Plugins > Add New” and look for the “User IP and Location” plugin.

I can guide you through this if you need help, just know that it’s a straightforward process.

get user ip and location, getting user ip in wordpress, getting user location in wordpress, user ip and location
Search for the Plugin

Once you spot the plugin, just hit the “Install Now” button and then give a quick click on the “Activate” button.

After the plugin is installed on your WordPress website, it is ready for use in your WordPress posts, pages, widgets, and custom post types.

Here are the shortcodes for accessing various information through this plugin:

  • User IP: [userip_location type=ip]
  • User City: [userip_location type=city]
  • User Region: [userip_location type=region]
  • User Country: [userip_location type=country]
  • User Country Code: [userip_location type=countryCode]
  • Latitude: [userip_location type=lat]
  • Longitude: [userip_location type=lon]
  • Timezone: [userip_location type=timezone]
  • ISP: [userip_location type=isp]
  • Flag: [userip_location type=’flag’ height=’auto’ width=’50px’]
details of user ip using "user ip and location" plugin
Details of User IP Using “User IP and Location” Plugin

Once you enter the details using the shortcodes shown in the image above, it will display the user details along with other important information to your readers.

get user ip and location, getting user ip in wordpress, getting user location in wordpress, user ip and location
Showing User’s Details on Frontend

Pro Tips: You can use these shortcodes to perform conditional actions based on a user’s details on your website. However, this may require a separate plugin or PHP code.

Code Snippets for Getting User IP

If you’re not comfortable using the “User IP and Location” plugin mentioned above, you can just use the PHP code provided to display users’ IP addresses on your website.

The code is easy to use – simply install a plugin called “Code Snippets” on your blog and then paste the code below.

If you put these codes into the “Code Snippets” plugin, then to show the IP address of people who visit your site, just use the shortcode [show_ip].

Generally speaking, I don’t suggest you go for this “Code Snippets” method, because it only lets you see the visitor’s IP address.

A Few More Plugins for Getting User IP Details

Apart from the “User IP and Location” plugin, here are a few alternatives to this plugin that you can try on your WordPress blog or website.

1. Show IP Addresses

get user ip and location, getting user ip in wordpress, getting user location in wordpress, user ip and location
Show IP Address

This plugin has not been tested with the top three major updates of WordPress; however, it continues to work smoothly, displaying the user’s IP address. It only shows the user’s IP address on the front end, so if you require additional details about the IP address, I do not recommend using this plugin.

However, if your main goal is to display the IP address on your blog, you can certainly give it a try. You can also use various other geo-IP location APIs to create your own user-tracking plugin/system.

2. Show Visitor IP

get user ip and location, getting user ip in wordpress, getting user location in wordpress, user ip and location
Show Visitor IP

This plugin functions similarly to “User IP and Location” but lacks several features available in the plugins mentioned above. Such features may include retrieving the user’s timezone, ISP, flag, etc.

Another aspect of this plugin that I found disappointing is that when I used it on my website hosted with Cloudflare, it displayed my hosting IP instead of the visitors’ IP addresses.

However, it is certainly one of the most installed plugins and works like a charm for your website—as long as you’re not using Cloudflare on your blog.

Wrapping Up!

In this guide, I tried to explain how you can get the IP details of users in WordPress and show it on the frontend. If you’re not quite sure about PHP and other programming languages, I strongly recommend using the plugins to get the IP details of the user and to do conditional things using it.

If you feel any issues using the plugin or have any doubts, then you can reach us at [email protected], or you can also share your queries in the comment section below.

Sunny Kumar

Number of posts: 163

Hi, I'm Sunny Kumar, a passionate tech enthusiast and a blogger from New Delhi, India. With a degree in IT from IIT-D and expertise in SEO, Cloud Computing, Telecom & Networking, and CEH, I specialize in various technical fields, including SEO, WordPress Development, and PC Building. And being a proficient WordPress user, I’m dedicated to delivering quality content and a remarkable user experience.

2 thoughts on “How to Get the IP Address and Location of Users in WordPress”

  1. Your article on fetching the IP address and location of website visitors is remarkably helpful. The WordPress plugin ‘User IP and Location’ you mentioned seems really useful for enriching user data. Thanks for sharing this valuable piece of information!

    Reply
  2. Great post on how to get user IP and location in WordPress. Your detailed guide with the step-by-step process is incredibly helpful for beginners, and the plugin recommendations are quite useful too. Thanks for sharing!

    Reply

Leave a Comment