Skip to content

Instantly share code, notes, and snippets.

@Lego2012
Last active September 29, 2023 15:50
Show Gist options
  • Save Lego2012/3f65e1606951c0385c935d5f2adbb88c to your computer and use it in GitHub Desktop.
Save Lego2012/3f65e1606951c0385c935d5f2adbb88c to your computer and use it in GitHub Desktop.

The WordPress Codex offers an interesting snippet for a shortcode. First copy the following code into the functions.php of the theme or use WP Code Box:

function wpcodex_hide_email_shortcode( $atts , $content = null ) {
	if ( ! is_email( $content ) ) {
		return;
	}

	return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}

add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );

Subsequently, an email address can be linked and encoded via the shortcode. The use in the WordPress editor looks like this, for example:

[email]info@somedomain.com[/email]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment