After setting up a typecho blog, you may find that if you insert some small emojis, they will not be displayed on the page, and all the content after the emojis will disappear, resulting in a poor user experience.
The reason why the emojis cannot be displayed is due to the issue with utf-8 encoding, which cannot recognize small emojis. It needs to be changed to utf8mb4.
Step 1: Access the database#
First, log in to the database of the blog's backend, then click on "SQL" and enter the following code:
alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_options convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_users convert to character set utf8mb4 collate utf8mb4_unicode_ci;
Simply copy and paste the code, then click on "Execute" in the lower right corner.
Step 2: Modify the typecho configuration file#
I am using the Baota panel. Click on "Websites" on the left side, then click on the root directory of our website. After entering, you can find a file named "config.inc.php" and open it. Scroll down to the bottom.
You can find 'charset' => 'utf8',
below. For better display, I commented it out and rewrote it. In actual operation, you just need to change utf8
to utf8mb4
.
/** Define database parameters */
$db = new Typecho_Db('Pdo_Mysql', 'typecho_');
$db->addServer(array (
'host' => 'localhost',
'user' => 'blog',
'password' => 'blog',
/** 'charset' => 'utf8', */
'charset' => 'utf8mb4',
'port' => '3306',
'database' => 'blog',
), Typecho_Db::READ | Typecho_Db::WRITE);
Typecho_Db::set($db);
Re-enter the small emojis in the article backend, then save and go back to the page. The small emojis will be successfully displayed.