![]() PS: Since you’re outputting that URL into an HTML context, you should HTML encode the URL again to make sure it doesn’t break your HTML syntax. There may be other ways to get the original title without HTML entities directly from WordPress without needing to do the complicated html_entity_decode dance, but again, I don’t know a lot about WordPress. Putting it all together, this should hopefully do it: echo urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')) The HTML-decoded value then needs to be URL-encoded, so it doesn’t screw up your URL syntax. you need to HTML-decode it to turn & back into the actual value &. What you want is to get the text without HTML entities, i.e. Meaning, it contains & instead of &, so that’s the value that is being sent to Twitter if you send it just like that. I don’t know the intricacies of WordPress, but I think get_the_title() returns a value that is already HTML escaped. ![]() To avoid that, you need to urlencode the text, which turns & into %26.Įncoding & to & is only necessary for & characters in HTML, which you should not have in your text, since all &s are replaced by %26. a&b., that does not represent the text “a&b”, it represents two separate parameters. & has a special meaning in URLs to separate several parameters.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |