WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is probably pretty simple, but...

I want to use the WP function antispambot not on get_the_author_email but on a value in a field I added to User Profile called publicemail. Everything I've tried throws a php error.

This is the antispambot usage shown in the WP docs:

echo antispambot(get_the_author_email());

And this is the complete function I'd like to get to work with antispambot and have it encode publicemail:

if ( !empty( $curauth->publicemail )){
echo 'Email &nbsp; <a href="mailto:' .$curauth->publicemail.' ?subject=Webmail">
<img src="' . get_bloginfo('template_url') . '/images/email_16.png"></a>'; }
share|improve this question
And where's the antispambot usage? Btw: Afaik, you should only use it on $curauth->publicemail, which should be the actual email. – kaiser Feb 28 '12 at 8:53
Exactly; I only want to use antispambot on $curauth->publicemail, i.e. antispambot($curauth->publicemail) which doesn't work. – markratledge Feb 28 '12 at 14:14
What does "doesn't work" exactly mean? – kaiser Feb 28 '12 at 14:20
No display of an email address - either plain text or encoded - in between the mailto: link and the ?subject=Webmail text. – markratledge Feb 28 '12 at 17:56
wow I can't believe they included that function in the core :) – onetrickpony Feb 28 '12 at 19:51
up vote 1 down vote accepted

As the Codex states for the antispambot() function:

Return Values (string) Converted email address.

You have to do one of the following:

echo antispambot( $curauth->publicemail );
// OR...
print antispambot( $curauth->publicemail );

So your full example would look like the following:

if ( ! empty( $curauth->publicemail ) )
    echo 'Email <a href="mailto:'.antispambot( $curauth->publicemail ).'?subject=Webmail">
    <img src="'.get_bloginfo('template_url').'/images/email_16.png"></a>'; 

About the difference between echo, print and (just) return

  1. echo and print are just synonyms/alias for each other and actually display something on the screen. The only difference in usage is, that you can't use echo in combination with return.
  2. return just gives something back as a functions output. In combination with print, a function can actually display something in a template, etc.
share|improve this answer
Ah, that was the problem. Works fine now. Thanks! – markratledge Feb 28 '12 at 23:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.