There are a couple of ways you can achieve what you asked for but the latter is what I’d recommend:
-
Set up a copy of the site in a different directory and using your web host’s control panel map the different domains to the appropriate directories. Use the same
DB_NAME
/DB_USER
/DB_PASSWORD
/DB_HOST
in the/wp-config.php
file for each of your sites but include different defines forWP_HOME
andWP_SITEURL
in each file. You might run into a few glitches but I think you can work through them by asking more questions here on WordPress Answers. -
Use one site with two different themes, add logic in
/wp-config.php
to recognize the different domains, and various hooks you might need to get things to behave as you want especially including one to load the right theme. What follows is (some of?) the code you’ll need for option #2.
Using One Site with Two Different Themes:
This code goes in your /wp-config.php
file anywhere before require_once(ABSPATH . 'wp-settings.php');
:
$this_domain = $_SERVER['SERVER_NAME'];
switch ($this_domain) {
case: 'www.savingsulove.com':
case: 'www.savings4biz.com': // I made up this domain to enable this example
define('WP_HOME',"http://{$this_domain}");
define('WP_SITEURL',"http://{$this_domain}");
default:
echo 'Invalid domain';
die();
}
Then to switch the theme based on the domain use the template
hook with the logic below. Probably the best place to put this code would be in a “Must Use” plugin; i.e. put the following into /wp-content/mu-plugins/savingsulove-theme-switcher.php
. This code assumes you’ve got two themes in the respective subdirectories /wp-content/themes/savingsulove/
and /wp-content/themes/savings4biz/
.
/*
File Name: savingsulove-theme-switcher.php
Plugin Name: Switch the Theme Based on Domain
*/
add_action('template','savingsulove_template');
function savingsulove_template($template) {
if ($_SERVER['SERVER_NAME']=='www.savingsulove.com')
$template="savingsulove";
else
$template="savings4biz";
return $template;
}
Beyond that, you can add any other shared code as a “Must Use” plugin like above (or just add more code to the savingsulove-theme-switcher.php
file) where you just inspect the value in $_SERVER['SERVER_NAME']
to decide what to do. If you need help with any additional aspects that might occur, just ask another question here (as opposed to adding follow up questions in the comments on this page after this question has been answered.)
P.S. There are more maintenance-free ways I could have written the above code but then it would have been more obscure and harder for a reader new to the techniques to follow what I was doing.