Monday 22 April 2013

Wordpress UTF8 Permalinks - UTF 8 Slug

In wordpress, to have longer article slugs so it can support long titles in UTF8 or Unicode:

1. In file wp-includes/formatting.php, replace 200 (1000 should be enough):
$title = utf8_uri_encode($title, 200); --> $title = utf8_uri_encode($title, 1000);


2. In file wp-includes/post.php search for 3 lines like the model below and replace 200 (same new value as in previous file, 1000):
$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";

3. Open the mysql databse of your wordpress site:
In the table wp_posts: edit "post_name row" to support longer utf8 slug (set 1000)

The drawback: you have to backup your database before wordpress and do the following:
BEWARE

everytime you update wordpress core, wp will update db -> wp_posts -> post_name to default varchar = 200. this will cause all of your non-latin permalink that longer than 200 will cut off. your links will become 404 found. this cannot revert. you can change varchar back to 1000 but the slug that got cut won't be able to revert.

There're 5 resolution steps for this issue

ONE: BACKUP DATABASE EVERYTIME BEFORE UPDATE WORDPRESS CORE

TWO: DON'T USE AUTOMATIC UPDATE FOR WORDPRESS CORE / USE MANUAL UPDATE INSTEAD

THREE: YOU MUST EDIT SOME FILES BEFORE UPLOAD AND UPDATE WORDPRESS CORE

OPEN FILE wordpress\wp-admin\includes\schema.php

FIND post_name varchar(200) EDIT 200 TO 1000
FIND slug varchar(200) EDIT 200 TO 300, 500 OR MORE
FOUR: PACK WORDPRESS AS ZIP FILE AND UPLOAD TO YOUR FOLDER

FIVE: UPDATE WORDPRESS MANUALLY

YOU MUST DO IT EVERYTIME BEFORE UPDATE WORDPRESS CORE IF YOU THINK THIS IS SO HARD TO DO THEN DON'T CHANGE URL SLUG IF YOU THINK IT'S WORTH, JUST DO IT


Source: Stackexchange here

No comments:

Post a Comment