Support » Fixing WordPress » Need help obfuscating email with PHP

  • Resolved TrishaM


    Greetings – once again I need help from an experienced PHP coder.

    I’d like to use either a short code (preferred) or a custom field, to enter a name, for example [phil] and have a function turn that into an email address that is obfuscated using a table of such names=>obfuscated email addresses that I can set up ahead of time in a separate text file or .php file…..

    This is for a multi-user site for a non-profit org, and they will be entering events with event coordinator contact info – I don’t really want them entering an email address directly (because I also manage their email and don’t want to deal with high amounts of spam that could result from it), but they are not tech savvy enough to consistently remember to use an obfuscated email address (if they can even remember how to do it right in the first place).

    So to make it easy for them I’d like them to just be able to enter a short code, or secondarily a custom field, and have a function that does a “lookup” and replaces the short code or custom field with the obfuscated email address. There is a limited list of event coordinators so I can easily maintain the list used to to the lookup from.

    I hope I’m explaining this well enough….will elaborate if questions. Any suggestions?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Bump – anyone? It seems like a simple short code function to do a lookup and replace a short code with other text should be a simple thing for a decent PHP coder……any takers?

    Justin Tadlock


    WordPress God

    add_shortcode( 'person', 'person_shortcode' );
    function person_shortcode( $attr ) {
    	if ( $attr['name'] == 'justin' )
    		$email = '';
    	elseif ( $attr['name'] == 'johnny' )
    		$email = '';
    	if ( $email )
    		return antispambot( $email );

    Then, enter the shortcode like: [person name="justin"].

    Or, you could create individual people shortcodes:

    add_shortcode( 'justin', 'justin_shortcode' );
    function justin_shortcode() {
    	return antispambot( '' );

    And use like: [justin].

    Was curious after reading the above, so i echo’ed out the result of a string passed to antispambot()…

    The output is no different…
    Output after antispambot()…

    Did i miss something?

    Justin Tadlock


    WordPress God


    Look at the HTML source.

    That’s just an example of something’s that’s built into WP. You can, of course, exchange that with any other function.

    I did look at the source, both the same…

    Which is why i was a little puzzled… 🙁 …

    Are you getting different results?

    @greenshady – thank you so much! I think I can use the first example and where you show the $email = ‘’; I can replace that ‘’ with the obfuscated address – I’ll test it to see if it works…

    I’m not familiar with antispambot – I know it’s in the WP core code as a function and what it does, just like t3los_ I haven’t been able to successfully use it, so I use an application that gives me the HTML code that looks like this:

    Nevermind it won’t display the HTML obfuscation correctly, it just displays the mailto link here….sigh….

    But it displays and works correctly like any other email link – I’m sure it wouldn’t stop the very smartest spambots but it sure stops most…..

    I’ll give this a go and let you know how it works….

    many thanks again!

    UPDATE: Okay the first example given by greenshady works very well – I used it as is, including the use of antispambot instead of the other way I was thinking of, and it does display the email correctly while randomly obfuscating letters in the source code, which is great.

    The only downside is the the email is not a clickable (mailto) link. The application I’ve always used in the past to create obfuscated email addresses adds the a tag to make it clickable – all using HTML to keep it obfuscated – but when I tried to use that, it just displayed the HTML, not the email address….

    SO is there a way to add in the <a href=” etc to make it clickable?

    Many thanks again for all your help!



    Bump – any ideas on how to make the newly obfuscated email address (using antispambot) clickable?

    I still need some help – just need to be able to have the newly obfuscated email link clickable….

    Bump……Anybody? There MUST be a way to use antispambot to obfuscate a mailto link and still have it be clickable…..



    I think PrivateDaddy would work for you (obfuscated yet clickable mailto links). check it out at There’s also a WordPress plug-in




    See “For WordPress” in the top menu bar

    @trisham – I think this would work:

    <a href="mailto:<?php echo antispambot($email) ?>"><?php echo antispambot($email) ?></a>

    where $email is your email address

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Need help obfuscating email with PHP’ is closed to new replies.