Home » Php » php – Two wordpress sites using diiferent themes on the same database

php – Two wordpress sites using diiferent themes on the same database

Posted by: admin July 12, 2020 Leave a comment


I want to run 2 wordpress sites, one.site.com and two.site.com from the same database. Everything remains the same except for the theme.

  • one.site.com – Existing site
  • two.site.com – Should use one.site.com’s database except for the

Is there any way this can be done ?

Since theme details are stored in wp_options table is it possible for two.site.com to use it to display a different theme ? Say duplicating that table and making two.site.com use it ?

I appreciate any help.


Both the sites do not have any plugins.

How to&Answers:

The solution below did the job for me,

Install 2 WordPress sites on a single database.

Create new table in your database. Call it wp_options2 and copy everything from wp_options into this new table

In second install go to wp-config.php, and before if (!defined('ABSPATH')) add define( 'M7_OPTIONS_TABLE', 'wp_options2');

In second install go to wp-includes/wp-db.php on line 1009 and add code:

if (isset( $tables['options'] ) && defined('M7_OPTIONS_TABLE')) $tables['options'] = M7_OPTIONS_TABLE;

These codes should be added in public function tables function, before if (isset( $tables['users']) && defined('CUSTOM_USER_TABLE')))

I found this solution here, https://wordpress.stackexchange.com/questions/84313/how-to-run-two-wordpress-blogs-with-different-themes-and-with-single-database-an#answer-175494

Since we use the same database, links will be same on both the sites. I had a lot of images linked and I removed them using

.single a[href$=".jpg"] {
    pointer-events: none;
    cursor: default;  


You can run two sites from a single database but not from the same set of database tables as the stored data includes the site’s domain name.

There are two values in the options table: siteurl and home which are used. Using the same options table won’t work, even if you update options forcefully for each php run.

So you would need to use two databases.


My advice is to replicate base and run both sites on different databases.


This could probably be accomplished by using wildcard subdomains (https://codex.wordpress.org/Configuring_Wildcard_Subdomains).

It may be a little hacky, but you’d have to test the condition of your subdomain (maybe in wp-config.php?) and set the theme in the database (http://www.inmotionhosting.com/support/edu/wordpress/change-theme-in-db).

The only problem I could see with this is that your functions.php can change WP functionality, so a Parent theme with two Child Themes is probably a good idea(https://codex.wordpress.org/Child_Themes).