Are you looking for a way to display share via email link? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display share via email link in WordPress.
A simple link that opens users default email client to send an email to a friend or colleague. The second link is an extension to display an excerpt in the email body.
Instructions:
All you have to do is add this code to your theme’s single.php file or in a site-specific plugin:
<?php echo '<a href="mailto:type%20email%20address%20here?subject=I%20wanted%20to%20share%20this%20post%20with%20you%20from%20' . get_bloginfo('name') . '&body=' . get_the_title() . ' - ' . get_the_permalink() . '" title="Email to a friend/colleague" target="_blank">Share via Email</a>'; ?>
<?php <br>echo '<a href="mailto:type%20email%20address%20here?subject=I%20wanted%20to%20share%20this%20post%20with%20you%20from%20' . get_bloginfo('name') . '&body=' . get_the_title('', '', true) . '%20%3A%20' . get_the_excerpt() . '%20%2D%20%28%20' . get_the_permalink() . '%20%29" title="Email to a friend/colleague" target="_blank">Share via Email</a>';<br>?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 9 best WordPress events plugins and how to create a contact form in WordPress.
I receive an error when trying to implement either snippet. Here is the error:
We encountered an error activating your snippet, please check the syntax and try again. Error message: syntax error, unexpected identifier mailto, expecting , or ;
Hey Kathy,
Thank you for the feedback. We have just updated the code in the article above since it was outdated. Please try again and let us know.
I would also suggest you try WPCode, if you do need a simpler solution. It offers a free version that allows you to make this code change. You can read the WPCode review here if you need more help as well.
Hope this helps, and looking forward to your feedback 🙂