How to change ?lang=cn into /cn/

I’m trying to add languages to my wordpress driven website and i installed xili-languages plugin. Unfortunately it uses lang param to differentiate between languages and i rather have seen something like http://domain.com/cn/article-in-chinese/ rather than http://domain.com/article-in-chinese/?lang=cn

Related posts

Leave a Reply

2 comments

  1. Set permalink to (Post Name)

    or

    http://www.example.com/[blog_name]`/%post_id%/%postname%/`
    

    Add following code to functions.php of your theme:

    add_filter ( 'alias_rule', 'xili_language_trans_slug_qv' ) ;
    
    
    function xl_permalinks_init () {
        global $XL_Permalinks_rules;
        if (class_exists('XL_Permalinks_rules') ) {
            $XL_Permalinks_rules = new XL_Permalinks_rules ();
            add_permastruct ( 'language', '%lang%', true, 1 );
            add_permastruct ( 'language', '%lang%', array('with_front' => false) );
    
        }
    }
    
  2. You would like to write:
    http://domain.com/cn/article-in-chinese/
    so that wordpress understand :
    http://domain.com/article-in-chinese/?lang=cn.

    I think it will be easier to use http://domain.com/article-in-chinese/lang/cn/. You need to write a new rule and a new tag in WP rewrite rules (WordPress write those rules in your htaccess) with the functions add_rewrite_rules() and add_rewrite_tag().