Follow Brian Li (@DecryptoBL) on Twitter.
Follow Brian Li (@bwhli) on Instagram.

How to Fix WordPress Character Encoding

November 19, 2018

After a recent update to my About page, I saw that Japanese characters were being rendered as question marks. Since Japanese characters were immediately changed to question marks after hitting the “Update” button in the WordPress editor, I quickly ruled out a font-related bug as the cause of the issue. After some Googling and subsequent database exploration, I discovered that my web host’s default database character set is latin1 (ISO-8859-1), which doesn’t support Japanese characters.

To fix the default character set, I downloaded an SQL dump of my database and duplicated it for backup purposes. Next, I opened the SQL file in Coda 2. If you don’t have Coda 2, any other text editor should work as well.

Next, I replaced all instances of DEFAULT CHARSET=latin1 with DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci. This changes both the default character set and collation properties of the database. Next, I imported the fixed database into MySQL, overwriting the old one.

Finally, I ensured my wp-config.php settings were on the same page as my database by adding these two lines after my database hostname declaration.

define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', 'utf8mb4_unicode_ci');

Problem fixed. Japanese works just fine now. すごい!


Find me on Twitter, or send me an email.