How To Display User And Visitor IP Addresses On WordPress Using Shortcodes

Creating a shortcode to display WordPress visitor’s IP addresses

WordPressThere are many benefits when displaying user/visitor IP addresses inside your WordPress pages and posts, for one it’s a great crime deterrent, just like those security alarm signs outside offices and homes. If a malicious visitor decides to visit your WordPress website without an IP disguise, they will most likely see their IP has been identified and will ignore the WordPress website in question to avoid hairy situations. Displaying IP addresses on your website is also a great way to inform your visitors of their transmission control protocol, better known as internet protocol (IP) if they need to use this specific information.

  • We have created a WordPress functions snippet which will allow you to display user and visitor IP addresses utilizing the shortcode [ user_ip].

Down Copy and paste the snippet below into your theme’s functions.php file

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

Use shortcode: [ user_ip] in pages and post or include the use of shortcodes in template files and widgets.

To properly use the shortcode remove the space before the first letter.
BBPress Shortcode Example

  • CodeGT

    Great thanks for this tip! I found it with my first search on google! You saved me a lot of time that I would’ve spent researching.