5

I have a WordPress installation at the document root for a domain, and then an additional installation in an immediate subdirectory of that installation such that I may use different themes for the two. I want to link the two sites logins so that you don't have to login twice in order to use both sites.

My coding skills are not great, so an easy fix or an of the shelf plugin are preferred.

  • Are you talking about a subdomain, or simply a sub-directory? A subdomain would be something along the lines of subdomain.bradleycountypulse.com, but all you mention is the /classifieds sub-directory (or URL component). Assuming that both URLs use the same WordPress installation and same database, there is no reason that the two would not already share the same login session... Have you installed WordPress twice? Is there any reason that you need to have two separate WordPress installations? – bosco Jan 27 '14 at 20:54
  • Playing around with your linked site, it appears to me as though you do indeed have two seperate WordPress installations - one located at bradleycountypulse.com and the other at bradleycountypulse.com/classifieds. Or is this a single multisite installation? – bosco Jan 27 '14 at 20:57
  • I had to use two installs because of the unique features of the classifieds page, a special theme was needed. – Jason Jan 27 '14 at 20:59
  • I wanted to use the sahifa theme for the main site, and then have classifieds pick up after clicking that link – Jason Jan 27 '14 at 21:01
  • In the event you need multiple sites for, e.g., a company intranet that needs to share logins, the Google Apps Login plugin is perfect (if your company uses Google Apps, o' course). – Ryan Feb 8 '16 at 22:33
5

You can share user tables between different WordPress installations by installing the second site ("Site B") to use the original site's ("Site A") database, then choosing to use an alternate table prefix during installation so as to keep the rest of the data separate.

The second part of the problem is sharing login cookies between the two installations (what WordPress uses to keep track of login/"session" data). In order to do this, you must use the same cookie-path for both sites.

After installation, open the wp-config.php file in Site B's installation root, and add (or replace) the following lines shortly after the database configuration, modifying them as needed to fit your configuration:

$cookiehash = md5("http://www.bradleycountypulse.com/");  // Use Site A's URL

define(CUSTOM_USER_TABLE,'wp_users');           //Change 'wp' to match the prefix set during
define(CUSTOM_USER_META_TABLE,'wp_usermeta');   //  Site A's installation
define('COOKIEPATH', '/');                      //This path should reference Site A's root
define('SITECOOKIEPATH', '/');                  //Should match 'COOKIEPATH'
define('COOKIEHASH', $cookiehash );

Note that this will only work if the two installations reside on the same domain (which yours do!).

An alternate solution would be to setup the entire system as a single multisite installation.

Still another solution (albeit one that requires more legwork) would be to employ custom page templates on a single installation.

  • Thank you, I think I can handle that! I will delete the second WP install and attempt to share databases. – Jason Jan 27 '14 at 21:55
  • Sure thing! Let me know how it goes - I've never actually done this myself. We may need to do a little finagling to get everything working properly. – bosco Jan 27 '14 at 22:32
  • thank you for this! I've been looking at 10s of solutions and no combination worked except this. – Mircea Sandu Feb 25 '16 at 17:57
  • I know this hasn't been updated in a while, but is it possible to use this method on a website that is already on a subdomain? – Weird Mike May 20 '17 at 21:29
  • @WeirdMike it should work as long as both sites share the same TLD. To use this method though, you'll have to do a little bit of a fancy database merge. The contents of the users and usermeta tables from the child site need added to the parent site's tables, respectively - but ID conflicts will need to be resolved. You might be able to use WordPress's import/export tool for this purpose. The rest of the child site's tables then need to be added to the parent db, giving them a new table prefix to keep them seperate from the parent's tables. Then, any field in the child site's new tables – bosco May 21 '17 at 2:22
0

I have released a wordpress plugin based on the following article:

http://subinsb.com/set-same-cookie-on-different-domains

User Session Synchronizer allows you to keep the user logged in from one wordpress to another by synchronizing user data and cookie session based on a verified email.

The user email is encrypted based on the current user ip and a secret key shared by the synchronized wordpress installations.

You can find the plugin here:

https://wordpress.org/plugins/user-session-synchronizer/

And participate here:

https://github.com/rafasashi/user-session-synchronizer

protected by Community May 7 '15 at 14:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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