Sometimes you need to know a visitor IP address in your wordpress website. That’s possible to detect and display a user’s IP. Now, you can read this short article that about how to retrieve the IP address and they are able to see their own IP address, of course.
It is a simple way, you can copy the following code snippet below. And you have to paste it in your theme’s functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//------- Display your user IP in WordPress function get_the_user_ip() { if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { // check user ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { // check user ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return apply_filters( 'ycf_get_ip', $ip ); } add_shortcode('show_ip', 'get_the_user_ip'); |
After that, you can add the shortcode
1 2 3 4 5 |
[show_user_ip] |
on your page, sidebar, or even post.
Here is a demo page about how to display a visitor’s IP address in WordPress.