X

Shortcode to Display Users IP address in Posts and Pages

Snippets by IsItWP

You can display the users IP addresses in posts and pages using a shortcode. It’ll help your users to know their IP address easily.

Instructions: Add the following code to the functions.php file of your WordPress theme.

function display_user_ip() {
	$ip = $_SERVER['REMOTE_ADDR'];
	return $ip;
}
add_shortcode('user_ip', 'display_user_ip');
[ip]

You may also enjoy appending shortcode after content in_category.

Comments  Leave a Reply

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

  2. IS NOT working !!!!!!!!!!!!!!

    1. Midhun Mathew July 17, 2013 at 3:08 am

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

    2. it works… if you are embedding, use

    3. 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.

  3. 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.

    1. Midhun Mathew July 17, 2013 at 3:08 am

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

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

    1. 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.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!