I am using qtranslate plugin for my WordPress site to make it a multi-language site.
Now I have got a requirement like
For English the url should look like www.sitename.com/contact-en
For French the url should look like www.sitename.com/fr/contact-fr
How can I accomplish this? (qTranslate is the plugin used)
Note: There should not be any post id coming in-between
As per the post in https://wordpress.stackexchange.com/questions/24061/multilingual-permalinks-qtranslate I tried http://www.3dolab.net/en/qtranslateslug-plugin-widget but ‘page not found’ errors are occurring. It looks like the author has stopped improving that plugin as per the 29th comment in that page.
In qTranslate settings in admin panel open advanced options and check the radio button for using language prefixes after domain name. I assume you have French listed in Languages settings of the plugin correct. You may expect dates shown incorrectly after that, use php date function to fix that in your particular language settings (edit language). Like j F. See primer at minexrussia.com/2011 where ru prefix is placed the same way.
To avoid en prefix, select english as default language and check setting in Advanced options for not to show prefix for default language. I suggest removing all other languages except en and fr in plugin settings.
Please have a look at http://wordpress.org/plugins/qtranslate-slug/
Having the “qtranslateslug-plugin-widget” plugin working in the admin side to store slugs in the slug table, I have put my own code in the user side.
In the
wp-blog-header.php
page I have added my own code just before the inclusion ofwp-load.php
file. I took the url from$_SERVER['REQUEST_URI']
, and using the slug and language in it, retrieved the post name and assigned the modified URIto $_SERVER['REQUEST_URI']
appropriately.For example:
Before I edit:
$_SERVER['REQUEST_URI'] = '/fr/french-slug';
After I edit:
$_SERVER['REQUEST_URI'] = '/post-name';
Let me explain it in a little more detailed way
Assign
$_SERVER['REQUEST_URI']
to a variableGet the slug exploding it with slash (
/
)Check the slug in the slug database table which “qtranslateslug-plugin-widget” plugin is using and get the post id from there
Now using the post id get the post name from the post table.
Implode it in such a way as I have shown in the above example.
Assign it back to
$_SERVER['REQUEST_URI']