[Resolved] Which hook to use for a function?

Home Forums Support [Resolved] Which hook to use for a function?

Home Forums Support Which hook to use for a function?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #859668
    Mark

    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 );
    ?>
    #859695
    Leo
    Staff
    Customer Support

    Hi there,

    Where did you get the code from?

    Did the author specify where it should be added?

    #859710
    Mark

    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.

    #859730
    Leo
    Staff
    Customer Support

    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.

    #859734
    Mark

    I understand. Thanks Leo!

    #859759
    Leo
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.