# Spam-Protected Email Shortcode

> Adds an [email] shortcode that prints a clickable email address encoded so simple spam bots cannot harvest it.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: shortcode, email, spam
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-protection-shortcode/

## Code

```php
add_shortcode( 'email', function ( $atts, $content = '' ) {
    $atts    = shortcode_atts( array( 'address' => '', 'label' => '' ), $atts, 'email' );
    $address = sanitize_email( '' !== $atts['address'] ? $atts['address'] : wp_strip_all_tags( (string) $content ) );

    if ( ! is_email( $address ) ) {
        return '';
    }

    $label = '' !== $atts['label'] ? esc_html( $atts['label'] ) : antispambot( $address );

    return '<a href="mailto:' . antispambot( $address, 1 ) . '">' . $label . '</a>';
} );
```

## Notes

Example: [email]hello@example.com[/email] or [email address="hello@example.com" label="Email us"].

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Spam-Protected Email Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
