Weird character encoding in WordPress

21st September 2016

Reading Time:

I recently had to migrate an older WordPress site to a new server while building a replacement. As soon as I got it running – with an up-to-date version of WordPress – I noticed strange, stray characters. I certainly didn’t add them, so where do these come from?

Character encoding

This screenshot is from OS X, but on Windows you may see characters like these: Â â €

Character encoding and why it matters

I won’t go into too much depth about character encoding, but essentially all the content of your WordPress site is stored in a MySQL database, encoded in the UTF8 character set. The UTF8 character encoding set contains all possible characters, from letters to numbers and punctuation.

Early versions of WordPress (pre-2.3) didn’t specifically declare what character set to use at installation, so the default set – usually Latin1 – was used instead. WordPress, however, would still attempt to store your content in the UTF8 charset.

The result? A look at the front-end of your site showed all kinds of unusual and unexpected characters.

Fixing the problem

Once I knew what the problem was, I found a simple fix. No charset had been defined, so I added in the following two lines to my wp-config.php file.

define('DB_CHARSET', 'utf8'); /* Database Charset. */
define('DB_COLLATE', '');     /* Database Collate type. */

I saved the file, crossed my fingers and refreshed… and the problem was immediately fixed. Whether this will work 100% of the time I couldn’t say, but in the hopes that it will serve as a reminder to myself – and a possible help to others – I thought I’d better make note of it!

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *

About the author

Rik Kendell is a developer, designer and writer in Leeds, UK. Originally from Bradford but always from Yorkshire, he specialises in front-end, responsive websites and WordPress builds. Having worked in software houses, the radio industry and design, marketing and digital agencies Rik has almost 10 years commercial experience and has worked with clients ranging from the NHS, Sky and Skipton Building Society to McDonalds, Lamb’s Rum and Crabbies Ginger Beer.

Rik is also a keen writer, covering digital/tech news, gaming, food and short fiction. His blog posts, reviews and Tweets have been published by the BBC, the Evening Standard, a number of agencies and industry websites and Rik is a key contributor on a foodie website.