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

Suffering to get the IP address and location of the user in WordPress website and not sure how to grab the location of user along with the IP address? I know when you search here and there for the proper guide, you’ll find the option to get only IP information – and none of them actually share the ways through which you can grab the location as well as coordinates details of the user.

But your search ends here, depending on the needs of webmasters like you, I’ve created a similar plugin named “User IP and Location” for WordPress. This plugin is really helpful for getting the user location, IP, Geo Coordinates, and a lot more details when a user tries to visit your website. 

So if you’re not sure how to get the user IP and location, then read this guide completely to learn more 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 install this plugin, either you’ve to download the plugin files from the WordPress repository or login to the admin panel of your WordPress. Once you’re inside of your WordPress admin panel, visit “Plugins > Add New” and search for the “User IP and Location” plugin.

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 find the plugin, click on the “Install Now” button and then click on the “Activate” button. It will install and activate the plugin for you. 

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

Here are the shortcodes for getting 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 entered the details using the shortcodes shown in the image above, it will show the user details along with other important information to your reader.

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 also use these shortcodes to do conditional things based on the user’s details on your website. But it may require a separate plugin or PHP code.

Code Snippets for Getting User IP

If you’re not comfortable with using the “User IP and Location” plugin which I shared above, you can simply use the PHP code which I shared above to display the IP address of users on your website.

The code is simple to use, you just have to install a plugin named “Code Snippets” on your blog and then paste the code which I shared below.

// Display User IP in WordPress
 
function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} 
elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; }
else { $ip = $_SERVER['REMOTE_ADDR']; } return apply_filters( 'thewpx_get_ip', $ip ); } add_shortcode('show_ip', 'get_the_user_ip');

Once you add these codes in the “Code Snippets” plugin. You’ve to use the shortcode [show_ip] to display the IP address of users on your website.

I usually don’t recommend using this “Code Snippets” method, because it only shares the IP address of the user, and getting other details will get complicated for you. 

A Few More Plugins for Getting User IP Details

Apart from the “User IP and Location” plugin, here are a few alternatives of this plugin that you can give a 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 is not being tested with the top 3 major updates of WordPress but still, it works smoothly to show the IP address of the user. This plugin only shows the IP address of the user in the frontend, so if you need some additional details of the IP address, I don’t recommend using this plugin.

But you can surely give it a try, only if your main goal is to show the IP address on your blog.

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 works a lot similar to “User IP and Location” but it misses a few features which are available in the plugins I shared above. Some of these features can include getting the user’s timezone, ISP, flag, etc.

Another thing that I disliked in this plugin is when I tried using this plugin on my website hosted with Cloudflare, it shows my hosting IP instead of the IP address of users.

But surely, it is another most installed plugin which works like a charm for your website (only if 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 issue 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.

TheWPX is a blog where we cover topics related to Blogging, WordPress, SEO, and Affiliate Marketing.
All the information which is published on our website is collected through independent research and tests. The data is being verified through consultation with reliable sources.
Also, We constantly update the content on our website, keeping it fresh and relevant to our readers at all times.

Leave a Comment

Sunny Kumar

Sunny Kumar, Founder of TheWPX

Hola Amigos! I'm Sunny Kumar, Founder of TheWPX. A blog where I share my experience which I have gathered from my last 5 year journey in blogging with all the new bloggers struggling to make their first income.

Copy link
Powered by Social Snap