Made this button that will share a post’s excerpt and title in WordPress via the visitors email client:
<a href="mailto:?subject=<?php echo rawurlencode()(get_the_title('','', false)) ?>&body=<?php echo rawurlencode()(get_the_excerpt()) ?><?php the_permalink() ?>" title="Send a link to this post via email" rel="nofollow" target="_blank">Share this post via email</a>
It’s working fine for 99%. The only problem is that it show’s the ascii codes from the post’s body and title.
So for example, i get in the email body to see ‘ …
‘ instead of […]
How can I solve this minor problem?
Basically, you will probably need to decode your html entities that are returned by
get_the_title
andget_the_excerpt
via calls likeSo, in your case, you would have to wrap your calls to
rawurlencode
aroundhtml_entity_decode
:But beware that, depending on your usage of
html_entites_decode
if your excerpt contains quotes or doublequotes your markup may get messed up and it will not work, so you would need to filter these. Read the doc for more info:http://www.php.net/html_entity_decode
(Edit: You could pass the ENT_NOQUOTES parameter to html_entity_decode for excluding quotes from the conversion; but if your titles or excerpts contain quotes those will still will be displayed encoded in your email.)
Furthermore, if your title or excerpts contain user generated content you might open up a security hole when you reverse the encoded entities (e.g. for XSS injections). So I would suggest finding another way to send the email (e.g. some kind of recommendation plugin).