Wednesday, 19 March 2014

Display a User’s IP Address in WordPress

Recently one of our users asked us if it was possible to detect and display individual visitors’ IP address in WordPress. Our answer was of course it is. In this article, we will show you how to display user’s IP address in WordPress.
You can use this to create your own IP detection site. This way when a website visitor views your site, they can see their own IP address.
All you have to do is paste the following snippet in your theme’s functions.php file
// Display User IP in WordPress

function wpb_show_ip()
{
        $user_ip = $_SERVER['REMOTE_ADDR'];
        return $user_ip;
}

add_shortcode('show_ip', 'wpb_show_ip');
 
Next thing you need to do is add the following shortcode in your post, page, or in a sidebar widget.
[show_ip]
If you’re using the shortcode in your sidebar text widget, and it is not working, then you need to make sure that you enable shortcode for sidebar widgets.
 

No comments:

Post a Comment