Archived topic
Which hook to use for a function?
5 replies · Started by Mark on April 4, 2019
Not sure where to put the following hide email function in elements/hooks. wp_head seems to work but not sure if that is the best solution?
<?php
function remove_plaintext_email($emailAddress) {
$emailRegEx = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4})/i';
return preg_replace_callback($emailRegEx, "encodeEmail", $emailAddress);
}
function encodeEmail($result) {
return antispambot($result[1]);
}
add_filter( 'the_content', 'remove_plaintext_email', 20 );
add_filter( 'widget_text', 'remove_plaintext_email', 20 );
?>
Hi there,
Where did you get the code from?
Did the author specify where it should be added?
Found it on line. Just a simple function to help hide an email address from bots. Anyway, my basic question is can functions be added using the elements hook feature and if so where? wp_head, wp_footer, custom hook? I am trying to add a simple function without using a plugin or child theme. Thanks.
Your basic question doesn't really have a basic answer.
Yes hooks can be used to insert functions, but only when that function should be executed in that specific hook.
I understand. Thanks Leo!
No problem :)