• Skip to main content
  • Skip to primary sidebar
BMA

BeMyAficionado

Inspire Affection

How to Fix Weird Characters Seen on WordPress Blog?

December 27, 2017 by varunshrivastava Leave a Comment

I know how frustrating it is to see Weird Characters in your blog post. The weird characters that hinder the reading experience of a reader. I have been through all this, tried many different solutions present online but it was all futile. Until I landed upon a solution which is safe and easy to implement.

If you are looking for an easy solution to quickly get rid of all those weird characters you are seeing on your blog then you will love this article. In this article, I’m going to share that ONE solution that will solve your problem and get rid of unwanted characters.

[bctt tweet=”I Just Found The Best Article On The Web Explaining How to Get Rid Of Weird/Funny Characters From My WordPress Blog.” via=”no”]

Table of Contents

  • Cause Of Weird Characters
    • What causes those funny/weird characters to pop up on your WordPress blog?
    • Why not convert the tables to UTF8 encoding once and for all…
  • WP DB Migrate From Latin1 to UTF-8 (Using PHPMyAdmin)
    • Step #1. Export Existing Database with UTF-8 Encoding
    • Step #2. Create New Database With UTF-8 Collation
    • Step #3. Import UTF-8 Encoded Data To Your Newly Created Database
    • Final Step
  • WP DBMigrate From Latin1 to UTF-8 (Using UNIX Commands)
    • Step #1. Make a Backup of Your Entire Database
    • Step #2. Convert Existing Data to SQL file in UTF-8 Encoding
    • Step #3. Create New Database with UTF-8 Encoding
    • Step #5. Import UTF-8 Encoded Data into Your Newly Created Database
  • Conclusion

Cause Of Weird Characters

The cause of these weird characters is no more than Character Encoding. You might have heard of different character encodings (UTF8, UTF16, UTF32, Latin1, etc…) when it comes to the computer world. Well, this is one of those simple encoding problems where your computer expects data to be in some other form than what it actually is.

You could relate to this problem in the real world as communication gap between two people speaking two different but similar languages. You might understand most of the words in the conversation but there will always be a few words that will remain alien to both of you. This is what is happening on your blog right now.

I know this because I have been there. I searched all over the internet to find the solution and these were all the listed problems that I came across.There could be a lot of reason behind this encoding problem. Some of the common reasons that are listed on the internet are:

  • I started seeing weird characters after I upgraded my WordPress blog to a newer version…
  • I just moved my blog to a new host and started seeing all those weird characters ( â €™ ?) on the blog…
  • ported entire data to another database, etc…

Reasons could be many, but the solution to all those problems is the same.

What causes those funny/weird characters to pop up on your WordPress blog?

By default, the WordPress create tables in whatever encoding your database charset have. Most probably your database charset encoding would be Latin1because mine was the same.

database_table_encodings

WordPress expects data to be in UTF8 which you can see inwp-config.phpfile.

define('DB_CHARSET', 'UTF8');

WordPress did not provide a default UTF8 encoding before creating tables into the database for the first time. This results in wrong charset encoding. That is what has become the root cause for those funny characters on your blog.

You must be thinking, ah well, why can’t we simply tell WordPress about the database charset?

Exactly, this is one simple solution to all your problem. You could simply tell WordPress that the database tables have Latin1 encoding so translate the content from Latin1 before displaying it to the user.

define('DB_CHARSET', 'latin1');

But, there is one problem, it is not a full proof solution. You will still be saving UTF8 encoded content in Latin1 encoded tables and this will cause trouble at some time. The best option would be to eliminate the problem from the root.

Why not convert the tables to UTF8 encoding once and for all…

The best solution would be to permanently convert Latin1 tables to UTF8. There are a two recommended ways by which you can convert Latin1 to UTF8.

  1. PHPMyAdmin
  2. UNIX Commands on your server

I will be covering both the parts in a minute but before let me brief you about the entire process in plain English :p

This is a three-step process. First, you will have to export your database into a SQL file with UTF-8 encoding. Secondly, you will have to create a new database with UTF-8 collation. This will become the database for your blog so choose a nice name. Third and the last step would be to import the UTF-8 encoded SQL file into your new database.

Once you have performed all the necessary steps, you will point your blog to your newly created UTF-8 database and you will no longer see those funny characters on your blog.

Now, let’s get to work and migrate your WP DB from Latin1 to UTF8.

WP DB Migrate From Latin1 to UTF-8 (Using PHPMyAdmin)

I’m sure you will have access to your PHPMyAdmin dashboard. Almost every web host provider provides PHPMyAdmin to manage MySql database. This comes bundled with CPanel and I’m sure whatever host you are using, you will have access to PHPMyAdmin. (If you wish to perform the same using UNIX commands then move to second part of this article).

Step #1. Export Existing Database with UTF-8 Encoding

With PHPMyAdmin, you get a wonderful UI to export data. You just have to perform certain clicks and your data will be exported safely.

Go to Export tab on your PhpMyAdmin dashboard and select all the tables. These tables along with the data will be exported to a SQL file. Make sure you select all the tables and data to export.

PHPMyAdmin - Select All Tables to Export

Navigate to the Object Creation Sectionand select the following. Make sure you tick the AUTO_INCREMENT value and IF NOT EXISTS options. Refer the image below,

PHPMyAdmin - Object Creation Option

Last but not the least, Navigate to the Data Creation Option and select the following options. Once you have made the selection, click on the GO button and save the file on your computer file system. A dialog box will pop up, simply give a meaning full name to the file and save it.

PHPMyAdmin - Data Creation Option

Click on the save button

Cool, you have just exported your entire database into UTF-8 encoding. Next, you will create a new database and import this file into the new database.

Step #2. Create New Database With UTF-8 Collation

Great Job! You have successfully exported your entire database into a UTF-8 encoded data. It is time to create a new database with UTF-8 collation.

Click on the NEW link from the side navbar and it will take you to Create Databasepage as you can see below. Provide a meaningful name to your new database and select UTF8_bin as collation and hit the Create button.

PHPMyAdmin - Create Database with UTF-8 Collation

This will create a New Database in MySql with UTF8 collation.

Step #3. Import UTF-8 Encoded Data To Your Newly Created Database

Next and the final step towards migrating the Latin1 encoded database to UTF-8 is to import recently exported data from your old database into newly created one.

Select your New Database from the list.

Navigate to the Import tab from the top navigation bar where you will see an option to import SQL file.

Click on the Choose File button and select the previously exported SQL file from the dialog box that pops up.

PHPMyAdmin - Import UTF-8 Data File

Click on the GO button at the very bottom and the importing process will start. It will take a few seconds depending upon the size of your SQL file. Once done you will have a new database with your old data in the UTF-8 encoding. All the hard work is done here. You have created a UTF-8 encoded database for your blog.

Final Step

The only thing left to do is to tell WordPress to point to this newly created database instead of the old one. This is very simple to do. For this, you must have access to your WordPress files hosted on the server. You can access those files with the help of Filezilla (a free FTP client). You can click here if you do not know how to connect to your hosting server using Filezilla.

Moving forward, once you have connected to the server, navigate to the root folder where WordPress is installed and open wp-config.phpfile.

Find your old database name and replace it with the new one.

WordPress wp-config File Update Database Name

Great Work! You have successfully ported your entire Latin1 Database to UTF-8. Wait, you first need to go to your website and check whether everything is working in the way it is expected to work. If everything is working fine then quickly share this post now 🙂

  • SpeedUp Your WordPress Website For Google PageSpeed Insight
  • How to Embed Mailchimp Form In Your Blog Post For Maximum Page Load Speed
  • 25 Free Must Have WordPress Plugins Of All Time

WP DBMigrate From Latin1 to UTF-8 (Using UNIX Commands)

To be honest, this way of doing things is safer than doing it with PHPMyAdmin. With PhpMyAdmin, a lot of things happens behind the scene which we are not aware. This may corrupt our data and make it an unpleasant experience.

However, if you are doing everything by yourself with the help of UNIX commands then there is a very less possibility of doing mistakes. Atleast you will know what you are doing.

PhpMyAdmin is good for people who are on shared hosting and do not have access to their servers directly. But if you have access to the server then doing everything manually should be the best option for you.

Doing it with commands is easier to follow. You just have to fire commands in the same listed order. Now, that you have gone through the PHPMyAdmin way of doing this thing, it would make more sense to understand what actually goes behind the scene. Let’s start the migration process :p

Step #1. Make a Backup of Your Entire Database

The first thing that we do before performing any actions on the database is BACKUP. You should take a backup of your entire database if anything goes wrong.

Copy and paste the below command into your server. Replace the BOLD text with your database specifics.

-- Backup Database to a .sql file 
mysqldump --opt --default-character-set=latin1 --skip-extended-insert 
--user root --password my-database-name -r exp-my-database-name-latin1.sql 
--log-error=log-mysqldump-my-database.txt

After firing the above command, a new SQL file will be created in the same folder with the following nameexp-my-database-name-latin1.sql.To check the contents of your folder, fire command.

ls -ltr

This will list the entire contents of the folder. See the file at the end which has been created. This file contains your entire database in Latin1 format. This is the entire backup of the database.

Step #2. Convert Existing Data to SQL file in UTF-8 Encoding

This is the continuation of the same first step that we did with PHPMyAdmin. You have already exported your entire database, now you will have to convert the contents of the SQL file into a UTF-8 encoded SQL file. Don’t worry this is also very simple. You just have to fire below command,

-- Replace latin charset with utf8 charset and create new .sql file with utf8 encoding
replace "CHARSET=latin1" "CHARSET=utf8" "SET NAMES latin1"
"SET NAMES utf8" < exp-my-database-name-latin1.sql > exp-my-database-name-utf8.sql

This command will create a UTF-8 encoded content in the new file named exp-my-database-name-utf8.sql

Step #3. Create New Database with UTF-8 Encoding

In this step, you will create a new Database with UTF-8 collation. This will contain all the data encoded in the UTF-8 format that recently converted from Latin1. Go ahead and fire the below command to create a new database with UTF-8 collation.

Replace the BOLD text with your database name. This database will become the main database for your blog so choose a meaningful name.

-- create new database that will hold data with utf8 encoding
CREATE DATABASE MY-DATABASE-NAME_UTF8 CHARACTER SET UTF8 COLLATE UTF8_BIN;

This will create a new database in MySql with UTF-8_BIN collation and UTF8 charset. You can check that by firing below command,

SELECT SCHEMA_NAME 'DATABASE', DEFAULT_CHARACTER_SET_NAME 'CHARSET', DEFAULT_COLLATION_NAME 'COLLATION' FROM INFORMATION_SCHEMA.SCHEMATA;

This will show the list of all the database listed with their charset and collation. Just like in the image below,

database_table_encodings

Here you can check the difference between your previous and current database. Your database charset and collation will be different than thenewly created database.

Step #5. Import UTF-8 Encoded Data into Your Newly Created Database

This is the final step in the equation. You have backed up your database, converted it to UTF8, created the new database, now the final step is to import that UTF8 encoded data into your new database. Go ahead and import the entire UTF8 database into your new database.

Do not forget to replace the BOLD words with your database specifics.

-- Export utf8 encoded data to your new database.
MYSQL --DEFAULT-CHARACTER-SET=UTF8 --USER=ROOT --PASSWORD='MY-DATABASE-PASSWORD' 
MY-DATABASE-NAME_UTF8 < EXP-MY-DATABASE-NAME-UTF8.SQL;

Woohoo! You have just migrated your entire Latin1 encoded database to UTF8 encoded database without corrupting or damaging any data. Now head back to the Final Step section to replace old database name with the new one in the wp-config.phpfile.

  • Port Existing Website to WordPress – The Best Way
  • Checklist to Follow After Moving Your Website From HTTP to HTTPS

Conclusion

The purpose of this post is to get rid of those weird and funny characters that show on your WordPress blog. I’m pretty sure that by migrating your existing Latin1 database to UTF8 will solve your problem and disappear those funny characters from your blog post.

In the worst case scenario, if it does not solve the problem then it would mean that somehow those characters have been stored in your database. So you can check github gist to fire those SQL commands on your database and see if it works or not.

If this post solves your problem then click on those social sharing buttons and spread the word.

Related

Filed Under: Wordpress N SEO Tagged With: Latin1 to UTF8, Seeing Weird Chars, Weird Characters, WordPress DB Migrate

Primary Sidebar

Subscribe to Blog via Email

Do you enjoy the content? Feel free to leave your email with me to receive new content straight to your inbox. I'm an engineer, you can trust me :)

Join 874 other subscribers

Latest Podcasts

Recent Posts

  • Is The Cosmos a Vast Computation?
  • Building Semantic Search for E-commerce Using Product Embeddings and OpenSearch
  • Leader Election with ZooKeeper: Simplifying Distributed Systems Management
  • AWS Serverless Event Driven Data Ingestion from Multiple and Diverse Sources
  • A Step-by-Step Guide to Deploy a Static Website with CloudFront and S3 Using CDK Behind A Custom Domain

Recent Comments

  • Varun Shrivastava on Deploy Lambda Function and API Gateway With Terraform
  • Vaibhav Shrivastava on Deploy Lambda Function and API Gateway With Terraform
  • Varun Shrivastava on Should Girls Wear Short Clothes?
  • D on Should Girls Wear Short Clothes?
  • disqus_X5PikVsRAg on Basic Calculator Leetcode Problem Using Object-Oriented Programming In Java

Categories

  • Blogging
  • Cooking
  • Fashion
  • Finance & Money
  • Programming
  • Reviews
  • Software Quality Assurance
  • Technology
  • Travelling
  • Tutorials
  • Web Hosting
  • Wordpress N SEO

Archives

  • November 2024
  • September 2024
  • July 2024
  • April 2024
  • February 2024
  • November 2023
  • June 2023
  • May 2023
  • April 2023
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • November 2021
  • September 2021
  • August 2021
  • June 2021
  • May 2021
  • April 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • February 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016

Tags

Affordable Hosting (4) algorithms (4) amazon (3) aoc-2020 (7) believe in yourself (4) best (4) database (4) earn money blogging (5) education (4) elementary sorting algorithms (4) experience (3) fashion (4) finance (6) Financial Freedom (7) food (7) friends (3) goals (5) google (5) india (10) indian cuisine (5) indian education system (4) java (16) life (16) life changing (4) love (4) make money (3) microservices (9) motivation (4) oops (4) podcast (6) poor education system (4) principles of microservices (5) problem-solving (7) programmer (5) programming (28) python (5) reality (3) seo (6) spring (3) success (10) success factor (4) technology (4) top 5 (7) typescript (3) wordpress (7)

Copyright © 2025 · Be My Aficionado · WordPress · Log in

Go to mobile version