Wordpress: Make a mailto link with the post title in the subject line.
Yo. I was just visiting the blog of Jonathan Snook and came across a post that stated that he had just adopted a baby. I wanted to tell him, “Congratulations” in the comments, but the comments were closed, and there was a message there stating that anyone who wished could just send him an email regarding that subject. On my site and at Snook’s site, there is no contact form, just an email address. This got me to thinking about a couple of things. First, that it’s a good idea to encourage readers to comment via email or comment form, and second, that it would be easy to go one step further and make an email link on the post page that references the post in the subject line automatically.
First, your basic XHTML mailto link:
<a href="mailto:you@yourdomain.com"
title="Email me!">Email me regarding this post.</a>
Next, we add the subject line. We will insert this right next to the email address in the XHTML, and we will use the WordPress Template Tag, the_title to grab the post’s title and put it in the subject line:
<a href=
"mailto:you@yourdomain.com?subject=Re:%20<?php the_title(); ?>"
title="Email me!">Email me regarding this post.</a>
The ‘%20′ in the code insures that all email clients read the spaces so the words don’t jumble together. I’ve tested this in Outlook and the post title’s spaces show up also, but I’m not sure if that is the case with all email clients. As long as you make sure that the link is in The Loop, this will work. The only downside to using this method is a problem inherent to all mailto links, which is that they are really only useful to those with email clients installed on their computer. People such as myself who exclusively use web based browsers will have to just copy the link and paste it into their ‘To:’ line. Dems da breaks. Enjoy!