Trouble using antispambot()

I have a custom field in a theme that contains an email address and was pleased to find antispambot()

<p><a href="https://wordpress.stackexchange.com/questions/124180/mailto:<?php antispambot(the_field("queries_e-mail')); ?>"> <?php echo antispambot(the_field('queries_e-mail'));?></a></p>

It looks fine and works as intended (ie. it opens a compose mail window) but when I view the code source it doesn’t appear to be encoded.

<p><a href="https://wordpress.stackexchange.com/questions/124180/mailto:[email protected]"> [email protected]</a></p>

According to the Codex the default usage is :

<?php echo antispambot("[email protected]"); ?>

which should output:

&#106;&#111;h&#110;&#46;&#100;&#111;&#101;&#64;mysit&#101;.&#99;&#111;&#109;

However the encoding doesn’t appear to be working in my case.

1 Answer
1

I think the problem is echo vs return,

i.e. that you are using the_field instead of get_field.

What you’re trying to do is similar to this:

 antispambot( echo( '[email protected]' ) )

but echo returns nothing.

Please try:

<?php $email = antispambot( get_field( 'queries_e-mail' ) ); ?>

<p>
    <a href="https://wordpress.stackexchange.com/questions/124180/mailto:<?php echo $email; ?>"> 
        <?php echo $email; ?>
    </a>
</p>

Leave a Comment