Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two wordpress sites using diiferent themes on the same database

Tags:

php

wordpress

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 theme

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.

EDIT:

Both the sites do not have any plugins.

like image 238
Vinith Almeida Avatar asked Sep 11 '15 12:09

Vinith Almeida


3 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;  
} 
like image 123
Vinith Almeida Avatar answered Nov 15 '22 12:11

Vinith Almeida


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.

EDIT:

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

like image 21
Josip Ivic Avatar answered Nov 15 '22 11:11

Josip Ivic


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).

like image 44
David Angel Avatar answered Nov 15 '22 13:11

David Angel