Is there a way to obfuscate an email address link that's generated by a global variable? I tried using Sprout's Encode Email, but it doesn't seem to work with an email address I've generated by a global variable. Specifically, the global variable doesn't work within an anchor tag. For example, the following doesn't work with Sprout's Encode Email:

{% set email = "<a href='mailto:{{ emailContact.emailField }}'>{{ emailContact.emailField }}</a>" %}
{{ email | rot13 }}

In the code above, "emailContact" is the global set and "emailField" is the associated handle for the actual email address.

It'd be great to figure this one out, especially because it seems a lot of folks would want to use a global variable for a contact email address. Thanks!

  • What does the filter output? Also do you have dev mode enabled?
    – Fyrebase
    Dec 5, 2016 at 6:51

3 Answers 3


It might be that you're trying to parse the variables within quotes " as you set email so you're actually encoding {{ emailContact.emailField }} as a string, not the value it represents. Something like this should work:

{% set email = "<a href='mailto:" ~ emailContact.emailField ~ "'>" ~ emailContact.emailField ~ "</a>" %}

{{ email|rot13 }}

If you're using the SEOmatic plugin, it exposes an encodeEmailAddress() function that you can use in your templates:



There is also this EmailObfuscate plugin for Craft CMS which seems to add obfuscation via filter on strings.

{{ entry.body|emailObfuscate }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.