Function and usage of antispambot() in wordpress


Answers ( 1 )


    The antispambot() function in WordPress is designed to help protect email addresses from being harvested by spam bots. Here's a detailed explanation of the function and an example of how to use it:

    Function: antispambot()


    The main purpose of antispambot() is to convert characters in email addresses into HTML entities. This is a technique to obfuscate the email address, making it more difficult for automated spam bots to recognize and collect the email address for spamming purposes.


    antispambot( string $email_address, int $hex_encoding = 0 ): string


    1. $email_address (string, required): This parameter is the email address that you want to protect from spam bots.

    2. $hex_encoding (int, optional): This parameter controls the encoding type. When set to 1, the function uses hexadecimal HTML encoding for the email address characters. The default value is 0, which means no hex encoding is applied.

    Return Value:

    • The function returns the email address with its characters converted to HTML entities. This obfuscated version of the email address is less likely to be detected and harvested by spam bots.

    Sample Usage:

    Example 1: Basic Usage

    $email = "";
    $protected_email = antispambot($email);
    echo $protected_email;

    This example shows the basic usage of antispambot(). It takes a plain email address and converts it into a spam-protected version using HTML entity encoding.

    Example 2: Using Hex Encoding

    $email = "";
    $protected_email = antispambot($email, 1);
    echo $protected_email;

    In this example, the antispambot() function is used with hex encoding enabled. This provides an additional layer of obfuscation by encoding the email address in hexadecimal HTML entities.

    Practical Application:

    You can use antispambot() in your WordPress themes or plugins wherever you need to display an email address publicly. By using this function, you can reduce the likelihood of the email address being picked up by spam bots, thereby protecting it from unsolicited spam emails.

Leave an answer