1

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)) ?>&amp;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 ' &hellip;' instead of [...]

How can I solve this minor problem?

Eric
  • 177
  • 2
  • 13

1 Answers1

2

Basically, you will probably need to decode your html entities that are returned by get_the_title and get_the_excerpt via calls like

html_entity_decode(get_the_title())

So, in your case, you would have to wrap your calls to rawurlencode around html_entity_decode:

<a href="mailto:?subject=<?php echo rawurlencode(html_entity_decode(get_the_title('','',   false)))?> ...

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).

Michael Helwig
  • 530
  • 4
  • 12
  • If I insert html_entities_decode(get_the_title()) , than I'll get a fatal error: call to Undifined function html_entities_decode – Eric Dec 23 '13 at 12:13
  • Sorry, I misspelled it. Try `html_entity_decode()` instead. But you should definitely read the docs. – Michael Helwig Dec 23 '13 at 12:15
  • Stay's the same as rawurlencode() I've read the doc's, but I'm new to php so it's hard for me to understand what to do. – Eric Dec 23 '13 at 12:25
  • I think it's almost the same question as here: http://stackoverflow.com/questions/3483422/replace-entites-in-rawurlencode-i-e-lt-gt-quot?rq=1 Maybe this wil help. Thank you again – Eric Dec 23 '13 at 12:38
  • 1
    You are right, I missed correcing your rawurlencode call. Just for reference: It should work with wrapping rawurlencode around html_entity_decode like this: ` – Michael Helwig Dec 23 '13 at 13:30
  • Awsome! that solved it. Could you please edit your answer so I can accept it? Thank you very much! – Eric Dec 23 '13 at 13:54