wp-content » plugins » Display visitor IP address without any plugin

Display visitor IP address without any plugin

Here is how you can create a WordPress plugin with a shortcode to display the user’s IP address:

  1. In the ip.php file, include the code that registers the IP shortcode and defines the shortcode callback function:
<?php
/*
 * Plugin Name: IP
 * Plugin URI: https://wpxss.com/application/ip
 * Description: Provides a shortcode to display the user's IP address.
 * Version: 1.0
 * Author: Stefan Pejcic
 * Author URI: https://pejcic.rs
 */

function ip_shortcode( $atts ) {
  return $_SERVER['REMOTE_ADDR'];
}
add_shortcode( 'ip', 'ip_shortcode' );
  1. Now you can use the [ip] shortcode in the content of your pages and posts to display the user’s IP address. For example:
Your IP address is: [ip]

This will output the user’s IP address in the content of your page or post.

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended