- This topic has 14 replies, 4 voices, and was last updated 6 years, 1 month ago by
Peter.
-
AuthorPosts
-
October 1, 2018 at 3:40 pm #691095
John
I am looking for a way to ensure that an email address is hidden/encrypted from Spam Bots on my site. Is that something that can be done with GPP?
My understanding, and please correct me if I’m wrong, is that Forms automatically do this. But I have a couple of email addresses on pages that are not a part of a form and I want to protect these.
Any guidance would be greatly appreciated.
Thank You!
October 1, 2018 at 8:10 pm #691192Tom
Lead DeveloperLead DeveloperHi there,
You could create a shortcode like this:
add_shortcode( 'email', function( $attr ) { extract( shortcode_atts( array( 'address' => '', ), $attr ) ); $email = '<a href="mailto:' . antispambot( $attr['address'] ) . '">'; $email .= antispambot( $attr['address'] ); $email .= '</a>'; return $email; } );Then you could do this:
[email address="me@me.com"]October 1, 2018 at 9:38 pm #691217John
I have added the above code to a Code Snippet. I guess my next question might be…how do I apply the shortcode in a block of text on the page itself? For example, I have some text and am saying “For more information Email me at “me@me.com.” If I do that using the shortcode [email address=”me@me.com”], nothing shows on the frontend. What am I doing wrong?
So, where do I actually enter the shortcode created within the text?
October 2, 2018 at 4:59 pm #691981October 2, 2018 at 7:01 pm #692021John
Tom,
I finally have it working, at least visually. However, if I “Inspect Element” it’s still showing the mailto:me@me.com
What I am trying to do is Encrypt the address so it can’t be harvested. But it does appear to me that it’s still available for harvesting. Here is a link to the page so you can see what I mean.
https://journeysgp.walnutcreekhoa.com/privacy/
You will see the email address near the bottom of the page. I’d be very curious to know what it shows on your end. Is it still showing the mailto: link?
October 3, 2018 at 9:53 am #692659Tom
Lead DeveloperLead DeveloperHmm you’re right – that’s strange.
Perhaps it would be best to use something like this: https://wordpress.org/plugins/email-address-encoder/
October 3, 2018 at 4:25 pm #692890John
I’ll give that a try. Thanks, Tom!
October 3, 2018 at 9:01 pm #692986Tom
Lead DeveloperLead DeveloperNo problem 🙂
February 13, 2020 at 1:14 pm #1164558Peter
I tried Tom’s code and it works OK when you View Source but not when you Inspect Element. Perhaps the Inspector decodes it.
February 13, 2020 at 3:56 pm #1164649John
Thanks for the comment, Peter. I don’t know anything about coding to see if that could be what is happening. Tom will most likely chime in with a response.
February 13, 2020 at 4:57 pm #1164680Tom
Lead DeveloperLead DeveloperThat makes sense – developer tools will show you the HTML of what you actually see on the page 🙂
February 13, 2020 at 5:19 pm #1164692John
Thanks, Tom. I’m assuming there is no real way to actually encode the email address to prevent harvesting, even using the plugin. Do you know if Spambots can harvest what is seen in the Inspect Element? I’m not sure how those things work and how much detail they actually try to harvest. Any insights about that?
February 14, 2020 at 9:37 am #1165557Tom
Lead DeveloperLead DeveloperIf I’m being honest, I’m not an expert with this kind of stuff.
If the email is visible on the site to the human eye, I assume there are ways for it to be harvested. If it’s visible to us, it’s visible to the inspector.
However, I do believe bots crawl the page source itself, which is where it should be encrypted.
May 16, 2020 at 7:51 am #1287341Matthias
Thumbs up from me for Toms Code
I tried to find out how to hide/encode my email – looking at wordpress codex (https://codex.wordpress.org/Protection_From_Harvesters)
Adding the code to my childs theme functions.php + shortcode into my contact page it just worked.
I had a look at the shown page source text and compared the gibberish to what a manual encoder shows (http://www.wbwip.com/wbw/emailencoder.html)
and its almost the same. The first 2 and last 2 letters aren’t encoded for some reason – but hey.Thx guys – one quick search on your site and again one of my todo-list problems is solved 😀
May 16, 2020 at 2:48 pm #1287803Peter
I’ve been using Tom’s code, but have tweaked it a bit to add a subject.
add_shortcode( 'email', function( $attr ) { extract( shortcode_atts( array( 'address' => '', 'subject' => '', ), $attr ) ); if ($attr['subject']) : $str_subject = '?subject=' . rawurlencode( $attr['subject'] ); endif; $email = '<a href="mailto:' . antispambot( $attr['address'] ) . $str_subject . '">'; $email .= antispambot( $attr['address'] ); $email .= '</a>'; return $email; } );rawurlencode is used to convert spaces to %20
The shortcode is then
[email address="me@me.com" subject="Enquiry through my website"] -
AuthorPosts
- You must be logged in to reply to this topic.

