Support » Requests and Feedback » Help international users by fixing this code

  • This will be a little longer, but I want to explain this issue in detail.

    As we all know, when using custom permalinks, titles of posts, categories, tags are used in urls. There are some functions for Latin scripts that do converting from non-English letters to English one (i.e. Šljivić becomes sljivic in URL).

    But problem is with non-Latin script. For example, in Serbian language we use Cyrillic script but in URLs we use English letters, so to achieve this in WordPress we manually transliterate to English letters, so that Здраво свете became zdravo-svete, not здраво-свете, which is actually shown as %D0%B7%D0%B4%D1%80%D0%B0%D0%B2%D0%BE-%D1%81%D0%B2%D0%B5%D1%82%D0%B5 . So we want that this transliteration is done automatically.

    Since this is not exclusively related to Serbian language, developers from other languages already worked with this and made several plugins but all of them have some issue that should be fixed.

    Two plugins that have slightly different code make same results and they are close to how they should work. Those are MK to Lat and Rus-to-Lat.

    If we install this plugin, all Cyrillic letters from titles of posts/pages/tags/categories are transliterated to Latin one in URL slugs for new posts/pages/tags/categories, but problem is that if there are already posts/pages/tags/categories with Cyrillic letters, those pages return 404 errors. (just to note that if we turn off plugin everything works without problem)

    Lets say we have post with title Један and URLједан (which will in address bar look like ). This page is opened without problem. Now we install one of two plugins above; we make new post titled Два but we now don’t get URLдва ( ), but instead get what we wanted, .
    Until now everything looks like there is no problem. But if we try to access pageједан we get 404 error. If we turn off plugin, we could again access that page (and also second page) without problems. If we again turn on plugin, we again can’t access first page.

    So, problem is with old slugs that contain Cyrillic letters.

    How should plugin work: for new slugs it should work as it works now, but it shouldn’t touch other slugs made before plugin’s installation.

    I will put code of both plugins below (without comments from top of files). If there is need for further explanation I’ll try to explain it. Thanks in advance

    MK to Lat

    function sanitize_term_translate ($title) {
    	$mk2lat_table = array(
    	global $wpdb;
    	if ($term = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE name='$title'")) return $term; else return strtr($title,$mk2lat_table);
    add_action('sanitize_title', 'sanitize_term_translate', 0);


    $tr = array(
    function sanitize_title_with_translit($title) {
    	global $tr;
       	return strtr($title,$tr);
    add_action('sanitize_title', 'sanitize_title_with_translit', 0);
  • The topic ‘Help international users by fixing this code’ is closed to new replies.