4

How do you run two Wordpress blogs with different themes using one database where the content remains the same in both sites? The issue that I am getting is at the Domain mapping in both blogs.

5
  • If you have multisite installed as per your question tag? then this should work just like what your asking. If multisite is not working can you be clearer on the issue and provide an example?
    – Shawn
    Commented Jan 9, 2014 at 20:44
  • @Aryan Please use same name for the theme then you can see the different theme in different domain like if your site on domain1 have active theme is theme1 then change the domain2 active theme name to theme one there are 2-3 steps you need to perform to change the theme name
    – Mitul
    Commented Jun 19, 2015 at 5:32
  • How can I customize the post status Commented Oct 27, 2020 at 11:28
  • Does this answer your question? WP Multisite: load content from site X on site Y
    – sampi
    Commented Feb 15, 2021 at 14:42
  • More solutions: stackoverflow.com/questions/32523635/… Commented Jun 5, 2022 at 8:34

5 Answers 5

4

I'll try to explain how it might be done, but not sure it will work:

  1. Install 2nd website with single db (2 copies).

  2. Create new table in your db. Call it wp_options2 and copy everything from wp_options into the new table

  3. in second install in wp-config.php, before if ( !defined('ABSPATH') ) add

    define( 'M7_OPTIONS_TABLE', 'wp_options2' );
    
  4. in second install go to wp-includes/wp-db.php on line 1054(for WP 5.6) and add this code:

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

    (This code should be added to the public function tables function, before if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) )

Now you should be able to change the theme, plugins atc. for the second theme, but all posts, taxonomies etc. will be doubled in both websites (wich is bad for seo btw.)

Should you run into problems with links on your second install, add:

define('WP_HOME','http://seccond_website.com');
define('WP_SITEURL','http://seccond_website.com');

in your wp-config.php file .....

but it wouldn't solve the problem if you were to create some post on the 1-st website, on the second website it would link to the first website...

I'll still post this answer, even though it's not correct (because of the problem described above).

As a solution you could create 2 separate installs with different $table_prefix and add an action to each move (save_post, save_taxonomies, save_postmeta etc.) to save from 1 db to the other, but changing the necessary links.

Or you could create a cron job on the second install to parse every post, page etc from the 1-st db to the 2-nd (since you have the access to both of them, it would be easy)

0

Not sure if it will be enough but this two plugins should give you most of what you want Any hostname - change the content urls to reflect the domain in which the content was requested Domain Theme - change the them according to the domain name.

I haven't tested any of them but it looks like even if they don't work you can get useful pieces of code from them.

0

If you have two separate WordPress installations (one per domain), you can define WP_SITEURL and WP_HOME in wp-config.php to force a specific address/hostname. Add this code to each wp-config.php:

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

And change example.com to the name of the domain in question.

0

Let me repeat your question in my words: you want two wordpress sites, using the same database and the same content. Just having a different theme and a different domain name?

That's duplicate content an google will rank both your sites badly for doing so.

I highly encourage you not to do so.

If you just want to share parts. Have a look at the switch_to_blog() function provided by WordPress multisite.

2
  • 1
    This answer was understandably downvoted. I upvoted it, bringing it back to a score of zero. Not because of the opinion expressed on what and what not to do, but because switch_to_blog() is useful information on where to start when attempting to share some content between sites. A couple of other useful puzzle pieces might be the filters plugins_loaded and template_include.
    – sampi
    Commented Jun 10, 2020 at 6:54
  • Thank you, yeah, todays me would probably give a way better answer. 6 1/2 years ago I was a WordPress rookie compared to today. Though my point "dont't do it, google doesn't like it" is still valid, more than ever. Unless someone has a precise plan of how to prevent this, it's still not a good idea to display content multiple times, no matter if the design changes or not. Commented Dec 13, 2020 at 9:21
0

You can change the theme based on the current domain like

function select_theme( $current_theme ) {
    if ( 'domain1.com' === $_SERVER['HTTP_HOST']) {
        return 'domain1 theme name';
    } else {
        return 'domain2 theme name';
    }
}

add_filter( 'stylesheet', 'select_theme' );
add_filter( 'template', 'select_theme' );

Not the answer you're looking for? Browse other questions tagged or ask your own question.