Approximate time to read: <1 minute
the_title will return the title of the current post. It’s stored in the database in plain text, however, when returned using the aforementioned functions if appears to be encoded. This means that characters such as ampersands and apostrophes will be converted to equivalents that are more HTML friendly.
Unfortunately, passing, say, this title to Twitter, via the URL, causes problems. First you have to URL encode and the mixture of the HTML encoding and the URL encoding produces a mess that Twitter simply doesn’t cope with very well.
However, the standard HTML decoding in PHP didn’t seem to work 100% with, for example, apostrophes not being decoded. After much head scratching and some frustration I found that this was due to the parameters that I was using.
The following line will correctly decode the post title to plain text…
To then encode is to be passed via URL, then simply use this…
It seems obvious now 😉