This plugin adds Twig filters to help you obfuscate email addresses (or any other content) in your templates.

This helps in thwarting spam bots that might crawl your website looking for email addresses to add to their mailing lists. The encoding logic is based on Dan Benjamin’s Hivelogic Enkoder.


The following Twig snippet will produce HTML where both the plain text email, and the mailto: anchor tag are recognised as emails and obfuscated.

{% filter enkode_emails %}
    Reach us on me@example.com or
    <a href="mailto:anotherme@example.com">here</a>.
{% endfilter %}

It will result in something like this (re-formatted for readability):

Reach us on

<span id="enkoder_1_2033799978">email hidden; JavaScript is required</span>
<script id="script_enkoder_1_2033799978" type="text/javascript"> /* <!-- */
function hivelogic_enkoder_1_2033799978() { … } hivelogic_enkoder_1_2033799978();
/* --> */ </script>


<span id="enkoder_0_1540754146">email hidden; JavaScript is required</span>
<script id="script_enkoder_0_1540754146" type="text/javascript"> /* <!-- */
function hivelogic_enkoder_0_1540754146() { … } hivelogic_enkoder_0_1540754146();
/* --> */ </script>.

More Filters

In addition to the enkode_emails filter, Obfuscator comes with a bunch of additional filters for more fine grained targeting of what to obfuscate.

    'Reach us on me@example.com or <a href="mailto:anotherme@example.com">here</a>.' |

{{ '<a href="mailto:me@example.com">Contact Us</a>' | enkode_mailtos }}

{{ 'Contact us at me@example.com.' | enkode_plaintext_emails }}

{{ 'I don’t want spam bots to read this.' | enkode }}

    'If you don’t have JavaScript, you’ll see a helpful message.' |
    enkode('JavaScript is required to view this message.')


Package Name

To install this plugin, search for its package name on the Plugin Store and click “Install”.


Report an issue