wordpress snippets last updated   : August 18, 2014
we now have 638 snippets

Shortcode to display users IP address in posts & pages

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will let you use a shortcode to display the users IP address in your posts or pages.

snippet :  PHPcopy
function display_user_ip() {
	return $ip;
add_shortcode('user_ip', 'display_user_ip');
snippet :  SHORTCODEcopy

Did you like this post? If so please share it with your friends. Thanks!

  • http://wpsites.net/ Brad Dalton

    What are the benefits of displaying the the users I.P address in your posts and pages?

    • Jaybe

      It’s just a choice, if you wanted to show someone you knew their IP. It really serves little purpose unless you’re wanting to point out, “Hey – I know where you’re coming from… here’s your address…”, or if you provide a service for your users that gives them their IP address as seen by/on the internet. Unless you have a need, I wouldn’t push that information out to the public.

  • Djenar

    I added this snippet to the function.php, but I didn’t see any IP address show on my website.
    Can you tell me more about this? Thanks.

    • Midhun Mathew

      You have to use ‘[user_ip]‘ as shortcode not ‘[ip]‘. Then it will work..!!!!

  • Patrick

    IS NOT working !!!!!!!!!!!!!!

    • Midhun Mathew

      You have to use ‘[user_ip]‘ as shortcode not ‘[ip]‘. Then it will work..!!

    • Carl

      it works… if you are embedding, use

    • Tape Roll

      Plz be kind to the code writer.
      He helped me a lot without contact.
      Change ip to user_ip.
      You could notice this litte mistake if you rewrite the code instead of it.

  • Guest

    You have to use ‘[user_ip]‘ as shortcode not ‘[ip]‘. Then it will work..!!!!!!

jqsnipp.com | we just launched jquery snippets website