WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've written a simple multi-language system, whereby clicking on a flag icon sets a one year cookie containing a two letter language code (e.g. nl, de, etc).

I hook into the wp action to read the cookie value, then use the the_title and the_content filters to show the correct language (the different languages are entered via metaboxes on the page/post edit screen).

This all works great except I'd also like to have permalinks for each language version whereby the two letter language code is between the domain name and the usual permalink structure. I'm using the %postname% permalink structure, so all the following would be valid:


If the current language is English, then no two letter code should be used (it will just be the normal permalink).

So far I have used the query_vars filter to add a query var called lang, but that's sa far a I've got, I'm unsure what the next steps are. Any advice much appreciated!

share|improve this question
thanks @l2aelba, that answer is close enough to what i need with some minor changes. – Simon Blackbourn Mar 27 '13 at 22:13
Do you have subdomains for this or just a single website – kennethjfalbous Mar 28 '14 at 8:42
just a single website – Simon Blackbourn Mar 28 '14 at 12:49

Your question is complicated enough to answer by myself, but I would suggest you to install qTranslate plugin. As the plugin's description says:

Choose one of 3 Modes to make your URLs pretty and SEO-friendly. - The everywhere compatible ?lang=en, simple and beautiful /en/foo/ or nice and neat en.yoursite.com

So you can try to inspect the plugin's code and see how they do it, or just use it at all.

share|improve this answer
thanks for the link, i'll take a look to see if i can deconstruct the code. – Simon Blackbourn Mar 8 '13 at 19:40

This is the filter I'm using:

function em_wpml_dbem_taxonomy_category_slug($option){
$lang = get_bloginfo('language');

if( $lang === 'es-ES' ){
    $option = 'eventos/categorias';
} else {
    $option = 'events/categories';
return $option;
add_filter('pre_option_dbem_taxonomy_category_slug', 'em_wpml_dbem_taxonomy_category_slug');
share|improve this answer
Please add an explanation to your answer - thanks. – ialocin Aug 26 '15 at 11:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.