JavaScripted e-mail Links in WordPress Pages

You may want to include an e-mail link in your WordPress Blog’s “About” page or elsewhere, but no doubt you don’t want this harvested and you’ve found you can’t simply add the JavaScript to the post or page as it gets nuked.

So how about a workaround?

Firstly, you need to create an external Javascript file with this code (amended for your own needs, obviously):

function obfuscate() {
var ppclink = "Click here to e-mail us";
var ppcname = "nospamthanks";
var ppchost = "yourdomainnamegoeshere";
document.write("<a href=" + "mail" + "to:" + ppcname + "@" + ppchost + ">" + ppclink + "")

NB: the “@” sign is represented in the code as “& # 64 ;” with no spaces.

Save it as something like emailobfuscator.js and upload it to your server.

Then in the post or the page you want to include it in, add the following code:

<script type="text/javascript"
src="/scripts/emailobfuscator.js" mce_src="/scripts/emailobfuscator.js">
<script type="text/javascript">

You will almost certainly want to uncheck the “Use visual editor when writing” checkbox in your User options before this will work.

And the finished result should look like this:

Writen by RHM

Join the discussion

This site uses Akismet to reduce spam. Learn how your comment data is processed.