How to Show User IP Addresses in WordPress
If you wish for your commenters to see their IP’s on your WordPress blog, this easy tutorial from Syed Balkhi and his team at WPBeginner will show you how to tweak your site’s code so it every time a user visits your site, they will be able to view their own IP address.
Simply paste the following snippet in your theme’s functions.php file or in a site-specific plugin.
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');
Then add the following code in your post, page, or sidebar widget. Just make sure that shortcode for sidebar widgets is enabled.
[show_ip]
That’s it!
If you have any further questions about the process, you can direct them to Syed right here.
Leave a Reply