Using more than one domain with qTranslate

Update: I have been able to restore the config file. This is not tested on the latest version of qTranslate and WordPress but should work anyway.

This was a question I kept asking myself and couldn’t work out how to do it. qTranslate (WordPress plugin) would only allow you to use subdomains for the different languages (such as en.domain or he.domain) or use paths (such as domain/en/ or domain/he/). For a while, I used the path for the different languages on Tweaked for your Pleasure however subdomains or the path sadly wasn’t enough for me.

I wanted to be able to use two different domains for the two languages. The main reason I wanted to do it is that I had the domains and I didn’t want to use subdomains. So, I wanted to see if anyone knew how to use different domains. On qTranslate forums, there weren’t any answers so I decided to have a look myself.

Now, I did work out a way to do it (and you can see it on this blog yourself) however my method works with hardcoding the domains into WordPress Config. I have changed this so that it does it all directly from the plugin so that you just type the domain you want into WP-Admin and which language to use however this change in the plugin hasn’t been released to the public. However, I will share the wp-config edits that I used. This will allow you to use different domains for each language.

First, make sure to set up each language in qTranslate and that you know each language code (in my example, en is English and he is Hebrew). Below is my wp-config file. Just change for each domain you use and with the language you use. My code below has some parts missing from the wp-config due to security reasons.

Do beware that there is a chance this will break your installation or won’t work with future upgrades but it works for me and very likely will work for you.

// ** MySQL settings ** //
$WhichLanguage = $_SERVER['HTTP_HOST'];
if ($WhichLanguage == "snat.co.uk" ) {

define('WP_SITEURL', 'http://snat.co.uk');
define('WP_HOME', 'http://snat.co.uk');

} else {
define('WP_SITEURL', 'http://snat.co.il');
define('WP_HOME', 'http://snat.co.il');
}

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);

// You can have multiple installations in one database if you give each a unique prefix
$table_prefix = 'wp_'; // Only numbers, letters, and underscores please!

// Change this to localize WordPress. A corresponding MO file for the
// chosen language must be installed to wp-includes/languages.
// For example, install de.mo to wp-includes/languages and set WPLANG to 'de'
// to enable German language support.
//define ('WPLANG', '');

/* That's all, stop editing! Happy blogging. */

define('ABSPATH', dirname(__FILE__).'/');

require_once(ABSPATH.'wp-settings.php');

if ($WhichLanguage == "snat.co.uk" ) {
$q_config['language'] = "en";
$q_config['default_language'] = "en";
} else {
$q_config['language'] = "he";
$q_config['default_language'] = "he";
}

define('COOKIEPATH', '/');

Need to reference?

Ellis, M. (2009). Using more than one domain with qTranslate. [online] Snat's Narratives & Tales. Available at: https://snat.co.uk/stem/scripts/using-more-then-one-domain-with-qtranslate.html [Accessed 21 Nov 2024].

Thanks for reading! You may be interested in this …

Join the Discussion

Update: I have been able to restore the config file. This is not tested on the latest version of qTranslate and WordPress but should work anyway. This was a question I kept asking myself and couldn’t work out how to do it. qTranslate (WordPress plugin) would only allow you to use subdomains for the different ... Read more

Add to the discussion!

This site uses Akismet to reduce spam. Learn how your comment data is processed.