David Artiss

Decoding a WordPress Post Title

Due to updates, over time, that have been made to the site and the age of this article, this post may not display correctly. In particular images may be missing or product reviews display incorrectly.

If this is the case and you'd particularly like me to fix it, then please reach out to me on Twitter.

By default, get_the_title and 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 😉

Categories: WordPress

What are Adobe up to? » « Which Android?

1 Comment

  1. 7 Years later and this info is still relevant and useful. Thank you David for sharing and keeping this post live 🙂

Talk to me!

Copyright © 2017 David Artiss

Theme by Anders NorenUp ↑

Scroll Up
%d bloggers like this: