Title: Language Switch
Last modified: August 21, 2016

---

# Language Switch

 *  Resolved [salemmarafi](https://wordpress.org/support/users/salemmarafi/)
 * (@salemmarafi)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/language-switch-1/)
 * I am trying to do the following:
 * Rewrite the URL structure of my WordPress installation so that a language field
   is in there. E.g. [http://www.mydomain.com/lang/](http://www.mydomain.com/lang/)
 * I want to then take the input from /lang/ and use it to display the appropriate
   content. E.g. if lang is ‘en’ I will take custom fields in English and display
   the theme in English.
 * Here is what I have so far:
 *     ```
       <?php
        function add_directory_rewrite() {
       	global $wp_rewrite;
       	add_rewrite_tag('%lang%', '(.+)');
               add_rewrite_rule('^/(.+)/', 'index.php?p=$matches[1]&lang=$matches[2]', 'top');
       	add_permastruct('lang', '%lang%');
   
          }
       add_action( 'init', 'add_directory_rewrite' );
       ?>
       ```
   
 * This works as far as getting the language but the problem I am facing is now 
   the_permalink() has “/%lang%/” where /en/ is supposed to be or /fr/ or /de/ or
   whatever language. To add more detail my permalink structure is /%lang%/%category%/%
   postname%/ and lets say I have a category called food and a post with the title
   chicken, the_permalink will generate [http://www.mydomain.com/%lang%/food/chicken/](http://www.mydomain.com/%lang%/food/chicken/)
 * Any idea what I’m doing wrong? Cheers.

Viewing 1 replies (of 1 total)

 *  Thread Starter [salemmarafi](https://wordpress.org/support/users/salemmarafi/)
 * (@salemmarafi)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/language-switch-1/#post-4436980)
 * For reference, solution is available here:
 * [http://stackoverflow.com/questions/20754505/wordpress-add-rewrite-tag-add-rewrite-rule-and-post-link](http://stackoverflow.com/questions/20754505/wordpress-add-rewrite-tag-add-rewrite-rule-and-post-link)

Viewing 1 replies (of 1 total)

The topic ‘Language Switch’ is closed to new replies.

## Tags

 * [add_rewrite_rule()](https://wordpress.org/support/topic-tag/add_rewrite_rule/)
 * [add_rewrite_tag](https://wordpress.org/support/topic-tag/add_rewrite_tag/)

 * 1 reply
 * 1 participant
 * Last reply from: [salemmarafi](https://wordpress.org/support/users/salemmarafi/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/language-switch-1/#post-4436980)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
