Title: Default language website
Last modified: August 31, 2016

---

# Default language website

 *  Resolved [giln343](https://wordpress.org/support/users/giln343/)
 * (@giln343)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/)
 * How can I define a default language with multilingual-press ?
    I mean if the 
   user have any of the website language, to redirect him to the default website.
 * By an example:
    I have 2 websites: fr.mysite.com mysite.com
 * I would like to specify mysite.com as being the default website. If a user go
   on fr.mysite.com and it’s language is anything except fr, redirect him to the
   default mysite.com.
 * Regards
 * [https://wordpress.org/plugins/multilingual-press/](https://wordpress.org/plugins/multilingual-press/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Thorsten Frommen](https://wordpress.org/support/users/tfrommen/)
 * (@tfrommen)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044187)
 * Hi (again ;)),
 * why would you want to do this?
    Please have a look at [this article on language negotiation](http://make.marketpress.com/multilingualpress/2014/03/language-negotiation-how-our-redirect-feature-works/).
 * Kind regards,
    Thorsten
 *  Thread Starter [giln343](https://wordpress.org/support/users/giln343/)
 * (@giln343)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044194)
 * Thks for your link.
 * Why I would do this ? for me everyone understand english. so if a non french 
   and no english browser user see a link of my website fr.donkeez.com, he have 
   to be redirected to my english version of website. It’s about usability.
 * The Russian user who click on fr.mywebsite.com should be redirected to my English
   version of website if I don’t have the russian version. no?
 *  [Thorsten Frommen](https://wordpress.org/support/users/tfrommen/)
 * (@tfrommen)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044212)
 * Ah, okay, so you only want to redirect users who don’t have French included in
   their language set at all. I originally assumed you (also) wanted to redirect
   users who might speak French, but not as first language (i.e., with a lower priority).
 * In order to redirect users who do not speak French at all, you could do something
   like this (assuming your English site’s ID is 1):
 *     ```
       add_filter(
       	'mlp_redirect_url',
       	function ( $url, $redirect_match, $current_site_id ) {
   
       		if ( 'fr-FR' === $redirect_match['language'] ) {
       			return $url;
       		}
   
       		if ( 1 === $current_site_id ) {
       			return '';
       		}
   
       		$urls = get_interlinked_permalinks(
       			get_queried_object_id()
       		);
       		$url = ! empty( $urls[1] )
       			? $urls[1]
       			: get_site_link( 1 );
   
       		return $url;
       	},
       	10,
       	3
       );
       ```
   
 * Kind regards,
    Thorsten
 *  [Thorsten Frommen](https://wordpress.org/support/users/tfrommen/)
 * (@tfrommen)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044219)
 * In case you already tried the above code, I just updated it. 🙂
 *  Thread Starter [giln343](https://wordpress.org/support/users/giln343/)
 * (@giln343)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044252)
 * I’m struggling in which file I have to put that ?
 * multilingual-press/inc/functions.php ?
 *  [Thorsten Frommen](https://wordpress.org/support/users/tfrommen/)
 * (@tfrommen)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044263)
 * Sorry.
    You can paste it into your **theme**‘s `functions.php` file.
 * Or you can create an MU plugin. For this, you just have to create a new file 
   in the `mu-plugins` folder (e.g., `wp-content/mu-plugins/mlp-redirect.php`). 
   If the `mu-plugins` folder doesn’t exist, just create it as well. Paste the following
   inside the new file:
 *     ```
       <?php
   
       add_filter(
       	'mlp_redirect_url',
       	function ( $url, $redirect_match, $current_site_id ) {
   
       		if ( 'fr-FR' === $redirect_match['language'] ) {
       			return $url;
       		}
   
       		if ( 1 === $current_site_id ) {
       			return '';
       		}
   
       		$urls = get_interlinked_permalinks(
       			get_queried_object_id()
       		);
       		$url = ! empty( $urls[1] )
       			? $urls[1]
       			: get_site_link( 1 );
   
       		return $url;
       	},
       	10,
       	3
       );
       ```
   
 * The advantage of this is that you keep the functionality even when you switch
   themes.
 * Kind regards,
    Thorsten
 *  Thread Starter [giln343](https://wordpress.org/support/users/giln343/)
 * (@giln343)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044445)
 * Hi,
 * I do have this error:
 * `Fatal error: Call to undefined function get_interlinked_permalinks() in /home/
   website/www/wp-content/mu-plugins/mlp-redirect.php on line 15`
 * So I’ve edited to `mlp_get_interlinked_permalinks`
 * But then I had `Call to undefined function get_site_link()` so i put `get_site_url`
   instead.
 * Is that ok ? it seems weird as result
 * >  $ curl -I -H “Accept-Language: en” “[http://fr.domain.com/&#8221](http://fr.domain.com/&#8221);
   > 2>/dev/null
   >  HTTP/1.1 302 Found Location: Array
 * >  $ curl -I -H “Accept-Language: fr” “[http://domain.com/&#8221](http://domain.com/&#8221);
   > 2>/dev/null
   >  HTTP/1.1 302 Found Location: [http://fr.donkeez.com/?noredirect=fr_FR](http://fr.donkeez.com/?noredirect=fr_FR)
 * >  $ curl -I -H “Accept-Language: ru” “[http://fr.domain.com/&#8221](http://fr.domain.com/&#8221);
   > 2>/dev/null
   >  HTTP/1.1 302 Found Location: Array
 *  Thread Starter [giln343](https://wordpress.org/support/users/giln343/)
 * (@giln343)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044446)
 * The correct code after debugging:
 *     ```
       <?php
   
       add_filter(
       	'mlp_redirect_url',
       	function ( $url, $redirect_match, $current_site_id ) {
   
       		if ( 'fr-FR' === $redirect_match['language'] ) {
       			return $url;
       		}
   
       		if ( 1 === $current_site_id ) {
       			return '';
       		}
   
       		$urls = mlp_get_interlinked_permalinks(
       			get_queried_object_id()
       		);
       		$url = ! empty( $urls[1] )
       			? $urls[1]
       			: get_site_url( 1 );
       		return $url['permalink'];
       	},
       	10,
       	3
       );
       ```
   
 * Thanks
 *  Plugin Author [Robert Windisch](https://wordpress.org/support/users/nullbyte/)
 * (@nullbyte)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044518)
 * Hi giln343,
 * can you tell me if that solves your question? We would mark this topic as resolved
   if so.
 * Kind regards
    Robert Windisch

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Default language website’ is closed to new replies.

 * ![](https://ps.w.org/multilingual-press/assets/icon-256x256.png?rev=2188271)
 * [MultilingualPress](https://wordpress.org/plugins/multilingual-press/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multilingual-press/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multilingual-press/)
 * [Active Topics](https://wordpress.org/support/plugin/multilingual-press/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multilingual-press/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multilingual-press/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [Robert Windisch](https://wordpress.org/support/users/nullbyte/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/default-language-website/#post-7044518)
 * Status: resolved