Adding WordPress' antispambot fuction to an email customizer field?

Greetings Y’all!

I’m trying to figure out how to add WordPress’ antispambot function to an email customizer field to add a little obfuscation to the address and I’m a little perplexed at how to go about it.

It’d like to use this code:
<a href="mailto:<?php echo antispambot( 'farm@moonlightprairiefarm.com' ); ?>"><?php echo antispambot( 'farm@moonlightprairiefarm.com' ); ?></a>

Which will be utilizing this WP function.

The current setup I’m using in the footer looks like this:

I could could probably hard code it in with a PHP Code action but keeping the field & link editable through the customizer would be preferred. Any advice and direction would be much appreciated. Thanks!

Before switching to FSE I always created my customizer fields in a one area (for me it was in my master.html page) and I never used the created version of it as an output. I always created a duplicate of the customizer field and use the “Don’t create the control, just display it” anytime I wanted to output it.

In your case, you can do the same. Create the control on a page that does not get exported to your theme (just to have its functionality) and then when you go to use your custom version of it, check the box I mentioned above and grab the PHP it will output (by using the </> icon top right of action). Then paste that PHP into a PHP function WP action and modify it with your antispambot() function around the output of the email address.

2 Likes

@jonroc Awesome! Thanks for the direction, I’ll give this a go.

I spent a couple hours again this morning trying out different approaches but didn’t hit anything that seemed to work so I appreciate this immensely.