Snippet: Add Mailto to all the e-mail addresses

Add following snippet to “functions.php”


function add_mailto($content) {
    $pattern = "/([a-z0-9][_a-z0-9.-]+@([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})/i";
    $replace = "\\1";
    $text = preg_replace($pattern, $replace, $content);
    return htmlspecialchars($content);


All the email address in post content will be changed to link with “mailto” functionality. This is not a good idea because of obvious spamming reason but it might useful for some people.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>