Veteran owned and
operated since 1998

How to Show Site Visitor’s IP Address on WP Forms Output

by | Mar 27, 2021 | Technical Help, WordPress

The WP Forms plugin for WordPress is fairly popular and one of the plugins I like using for handle form inputs on websites. I especially like being able to tie in Google RECAPTCHA into it which greatly reduces form spam.

Form spamming has become big business. Apps (pieces of software that scan the web looking for forms to fill in) are built on a regular basis to fill in forms with spam. Most website owners have little or no understanding of how and why they seem to get inundated by spam messages from their website forms. Often they think something has been hacked or they are subject to otherwise malicious intent. The fact is, their form was merely discovered and is being filled out by software rather than human beings.

Showing the site visitor’s IP address can help determine whether the output received from forms is “real” or not. It isn’t an absolute determination though. The site visitor may be using a virtual private network (VPN) which can hide their true IP address and only show the IP address of their VPN provider. But, in most cases, it will show an address from where the general location form output originated from.

Adding the IP address to WP Form output

One great thing about determining the IP address of a spammer, is that their IP address can then actually be blocked. They can be blocked from viewing or accessing entire servers. So, from the aspect of someone running their own hosting services as we do, that is a great piece of information to know.

What didn’t work for me

Adding templates to the theme did not work as explained within the WP Forms template files. I tried to do this in my child theme.

Inside each of the PHP file texts of the WP Forms templates are indications that one can insert a new copy of the template file within the theme structure. This is along the lines of how child themes actually work – they look for a file in the child theme first and use it before looking in the parent theme. I added the templates exactly as indicated within the templates themselves inside the structure of a site’s child theme to no avail.

It is important to make hard coding changes to a child theme and not the parent theme (hence the importance of using a child theme in the first place). Making coding changes to the original parent theme subjects your changes to loss upon theme updates to that original theme. Since I tried adding the templates to the child theme and it didn’t work, I quickly abandoned this method. I am never willing to add any hard coded files to the parent theme, so I sought another way to accomplish the task.

What did work for me

Adding code to the child theme’s functions file ultimately worked. While this method took much longer to discover a solution, it worked with an amazingly small amount of coding and only took a few minutes to implement (after many hours of trying all that didn’t work).

I searched for information about the WP Forms templates and ultimately discovered some developer geared help on their website. From that, I was able to glean a working copy of a function to add to my site that accomplished the job in a minimal amount of code.

So here is the finished code that I simply added to the end of my child theme’s functions.php file:

/* -- Start of CharlesWorks WP Forms ip address shortcode --*/
function wpf_ip_footer_text( $footer ) {
$footer = $footer . ' from IP address ' . $_SERVER['REMOTE_ADDR'];
return $footer;
}
add_filter( 'wpforms_email_footer_text', 'wpf_ip_footer_text' );

/* -- More info at https://wpforms.com/developers/how-to-remove-or-change-email-notification-footer-text/ --*/
/* -- End of CharlesWorks WP Forms ip address shortcode --*/

As you can see, this is a very simple piece of code that merely adds some text and the IP address of the site visitor on the tail end of the existing WP Forms footer message. But it does the job.

CLICK HERE to find your domain name!   CLICK HERE to transfer your domain name!

Resource Categories

Archives