Wordpress : Unable to save or update posts with Emoji
Asked Answered
C

1

7

I host my WordPress (v5.4.2) blog on 000webhost.com and I am unable to save any post with emoji characters. I get this error Updating failed. Could not update post in the database

I have tried changing these lines in wp-config.php

define( 'DB_CHARSET', 'utf8mb4' );

define( 'DB_COLLATE', 'utf8mb4_unicode_ci' );

I also migrated all my tables in MySQL to utf8mb4_unicode_ci with the below step. enter image description here

But none of these worked, what I am missing? Please help My WordPress version: 5.4.2

wp_encode_emoji()

Coheman answered 26/7, 2020 at 12:50 Comment(1)
I have the very same issue and tried all the first steps as having the right DB charset and collate. Moreover, it happened one day I haven't changed anything, which is strange and let me think it could be triggered by WordPress Crons..Poignant
L
12

Adding this code in functions.php fixed it for me:

add_filter( 'wp_insert_post_data', function( $data, $postarr ) {
if ( ! empty( $data['post_content'] ) ) {
    $data['post_content'] = wp_encode_emoji( $data['post_content'] );
}
return $data;
}, 99, 2 );
Ledesma answered 30/3, 2023 at 12:26 Comment(2)
This helped me when I added it to the end of the functions.php of the current theme using the Theme File Editor.Transubstantiation
I also had to include 'post_title' such as: $data['post_title'] = wp_encode_emoji( $data['post_title'] );Collide

© 2022 - 2024 — McMap. All rights reserved.