Site logo

[Resolved] Encrypting Email Addresses

Home Forums Support [Resolved] Encrypting Email Addresses

Home Forums Support Encrypting Email Addresses

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #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!

    #691192
    Tom
    Lead Developer
    Lead Developer

    Hi 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"]

    #691217
    John

    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?

    #691981
    Tom
    Lead Developer
    Lead Developer

    Hmm, seems to be working for me:

    2018-10-02_1657
    2018-10-02_1658

    #692021
    John

    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?

    #692659
    Tom
    Lead Developer
    Lead Developer

    Hmm you’re right – that’s strange.

    Perhaps it would be best to use something like this: https://wordpress.org/plugins/email-address-encoder/

    #692890
    John

    I’ll give that a try. Thanks, Tom!

    #692986
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

    #1164558
    Peter

    I tried Tom’s code and it works OK when you View Source but not when you Inspect Element. Perhaps the Inspector decodes it.

    #1164649
    John

    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.

    #1164680
    Tom
    Lead Developer
    Lead Developer

    That makes sense – developer tools will show you the HTML of what you actually see on the page 🙂

    #1164692
    John

    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?

    #1165557
    Tom
    Lead Developer
    Lead Developer

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

    #1287341
    Matthias

    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 😀

    #1287803
    Peter

    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"]

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.