Hiding email from source (cloak)

below link can be pasted as is in the html site.

put extra y’s in the email address.
the y will be removed on click.
I usually use x but in email@example.com there is an x which shouldnt be taken out.

For putting in a menu or any other template, I created a very simple partial (brankontact) with the following:

<a class="nav-link" href="mailto:yemyyyailyyy@exyyyamypyle.cyoym" onclick="this.href=this.href.replace(/y/g,'');" title="email me">Contact</a>

then call the partial from a template by

            {{ partial "brankontact.html" . }}

script creds go to my friend Branko Lankester

-automation in templates and change protocol via params.toml
-shortcode with option to different protocols

any template

{{ partial "brankontact.html" . }}

Params.toml

[themeSettings]
address = "myyaiyly@eyyxaymyplyye.cyomyy" # email address or telephonenumber
protocol = "mailto" # default: mailto. valid options: mailto, tel, sms, callto
class = "butmir"
display = "CONTACT"
title = "email me"

shortcodes

{{< brankontact >}}
{{< brankontact address="0yy0y4332y66y6yy131yy2y4y2" protocol="tel" class="butmir" title="contact" display="call me" >}}

shortcodes/brankontact.html

{{- $address := .Get "address" | default .Site.Params.themeSettings.address -}}
{{- $protocol := .Get "protocol" | default .Site.Params.themeSettings.protocol | default "mailto" -}}
{{- $class := .Get "class" | default .Site.Params.themeSettings.class -}}
{{- $title := .Get "title"| default .Site.Params.themeSettings.title  -}}
{{- $display := .Get "display" | default .Site.Params.themeSettings.display -}}
<a href="{{ $protocol }}:{{ $address }}" 
  onclick="this.href=this.href.replace(/y/g,'');" 
  class={{$class}} 
  target="_blank" 
  title={{$title}}>
  {{ $display }}
<a>

When you post code or data (including configs) in this forum, please use code fences or the < / > button in the menu.

```
my code
```

Related thread: Cloak email shortcode component

Thanks for sharing @mir !

more than welcome!

1 Like