Home Blog Get the IP Address of a Visitor with PHP (or WordPress Shortcode)

Get the IP Address of a Visitor with PHP (or WordPress Shortcode)


There are hundreds of functions found over the web that can be used to find the real IP address of a visitor. Here’s one function that works well for us. The function searches environmental variables, validates a likely IP against PHP5’s filter_var() function and then returns the value.

As with all IP-based (or HTTP header) tools, it’s easy to spoof. For the majority of purposes, though, it serves its purpose nicely.

Display a User IP Address with WordPress Shortcode

For the sake of it, here’s how you would display the IP of a visitor in a WordPress post or page with very simple shortcode.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

You may optionally download the WordPress plugin. Render the IP address of a user with [getip].


The shortcode of [getip] would return (your IP address).


If you wanted to expand upon the function, you could add geo-specific services to users, add maps, use custom geographically targeted titles, render custom advertising, display a geographic user plot, or deliver geographically appropriate content (such as local weather) – all of which we’ll be sharing in the future (it’s the purpose of sharing this simple function).


Title: Get the IP Address of a Visitor
Description: Return the IP address of a user with PHP or WordPress shortcode.
Download: Shortcode (V0.1) | WP Plugin (V0.1) | PHP Code (V0.1)

Shortt URL for this post: http://shor.tt/1XMy



Please enter your comment!
Please enter your name here