How To Display Visitor’s IP Address In WordPress

How To Display Visitor’s IP Address In WordPress. In this article we will show you how to display a visitor’s IP address in WordPress site.
You can also use this code to create your own IP detection site. The purpose of this code is to show the the IP address of the visitor who views your site. All the users visiting your site can see their own IP addresses.

Display Visitor’s IP Address In WordPress

To display visitor’s IP address on your website, just paste the following php code snippet in your theme’s functions.php file.

You can find functions.php file by going into admin panel>>appearance>>editor.

Step 1:

Paste Below Code in functions.php file.

// Display User IP in WordPress

function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return apply_filters( 'wpb_get_ip', $ip );
}

add_shortcode('show_ip', 'get_the_user_ip');

Step 2.

Add the following shortcode on your website’s page, post or anywhere you want to show the IP address to user.
[show_ip]

I hope this article will help you to display IP address of the visitors to your WordPress site. You can leave us a comment below for further query or feedback.

You May Like: 4 Ways To Earn Money Online Without Investment

Leave a Reply

Your email address will not be published. Required fields are marked *