I have post name in Thai which uses UTF-8
character. Many of them encode into super long in ASCII e.g. วิà¸à¸µà¸à¸²à¸£à¸«à¸¥à¸µà¸à¹à¸¥à¸µà¹à¸¢à¸à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸à¸à¸±à¹à¸-8-à¹à¸à¸à¸µà¸§à¸´à¸à¸à¸²à¸£à¹à¸à¹à¸à¸à¸²à¸
I’ve changed the type of “post_name” using phpMyAdmin to VARCHAR(1000)
and collation to utf8_unicode_ci
.
However, in my WordPress backend editor, the above post name is still automatically cut to วิà¸à¸µà¸à¸²à¸£à¸«à¸¥à¸µà¸à¹à¸¥à¸µà¹à¸¢à¸à¸à¹à¸à¸à¸´ when I try to save the URL.
There is this plugin that lift the character limit but it’s in Thai which I can’t read.
Any ideas?
It happens because when you save a post, WordPress calls
sanitize_title
function to sanitize your title. This function appliessanitize_title
filter.One of core hooks for
sanitize_title
filter issanitize_title_with_dashes
function, which checks title on utf8 format by callingseems_utf8
function and if the title has utf8 format, the function callutf8_uri_encode
function.utf8_uri_encode
function receives two arguments:$utf8_string
and$length
. The first one is your title and the second argument is the length, which the title shouldn’t overflow.sanitize_title_with_dashes
function passes your title with limit of 200 characters long. So if you want to change the limit you have to change standard hook forsanitize_title
filter. Here we come to a bit dirty solution, but however it should help you:As you can see we use completely the same
sanitize_title_with_dashes
function with one change: instead of passing200
, we pass1000
as the limit for title.