Skip to content

How to share users and logins between WordPress websites

Are you looking to share users and login sessions between two or more WordPress websites? If so, you can learn how to do it step-by-step by following this guide.

Recently, I found myself in a situation where I needed to add a bbPress and BuddyPress “section” to a website (we’ll call this site B), although the main website (site A) and site B were supposed to have different WordPress installs. Lucky for me, both websites were hosted on the same server so this made it the whole scenario easier.

After I finished it and got it working, I decided to write an article on it to prevent you from some of the headaches I got while doing this. Also, the process could be extended to as many websites as you need. In my case, I was only going to need to synchronize login details and cookies between two WordPress installs.

I’ve recently discovered this plugin, which seems to do the same thing and without all the work required in my tutorial. I now recommend giving WP Remote Users Sync a try instead.


  • Site A and Site B must be on the same top level domain (subfolders or subdomains)
  • Site A and Site B will be using the same Database

Probably obvious, but you will also need FTP access to both websites, we will be opening and editing wp-config.php for both websites. If you meet the requirements, we can move on.

(Optional) Take a full website Backup

Since we’ll be working with wp-config.php and the databases, it’s best to be safe and run a full website backup, or at least the database and wp-config.php. For this I recommend using Updraft Plus or WP Time Capsule, but just about any other solution will work. I recommend them because I’ve used them many times and never failed me.

Share Users and User Meta

In order to have the same login and password on both websites, we’ll be using the same database tables. If you’re using the default prefix, these should be called wp_users and wp_usermeta.

1. Check Site A’s table prefix

If you don’t know for sure your site’s table prefix, open Site A‘s wp-config.php and look for this line:

$table_prefix = 'wp_';
Code language: PHP (php)

In most situations, it will be wp_, but if yours is different just remember it because we’ll be using it for Site B‘s wp-config.php too. Keep wp-config.php open, we’ll be needing more info later, as well as to edit it.

2. Install WordPress for Site B

Keep in mind we’ll be using the same database as Site A, so you will have to use a different table prefix for Site B. In my example, I decided to use com_, short from Community. You can use whatever you see like, it doesn’t matter.
If you’re using tools for automated WordPress installation that do not allow you to select the database and prefix, don’t worry about it as you can change them later from wp-config. Just make sure you have WordPress installed in a Subfolder or Subdomain.

Open Site B‘s wp-config.php, and replace database name, user, and password to be the same as Site A.

define('DB_NAME', 'siteAdatabase'); define('DB_USER', 'siteAuser'); define('DB_PASSWORD', 'siteApassword');
Code language: JavaScript (javascript)

Now both sites will be using the same Database. Make sure Site B uses a different table prefix.

$table_prefix  = 'com_';

3. Share WordPress Users between the websites

To do this,  all we need to do is to make sure Site B is using the same tables for users and usermeta as Site A. Open Site B‘s wp-config.php and add the following lines right before 
/* That’s all, stop editing! Happy blogging. */

define( 'CUSTOM_USER_TABLE', 'wp_users' ); define( 'CUSTOM_USER_META_TABLE', 'wp_usermeta' ); /* That's all, stop editing! Happy blogging. */
Code language: JavaScript (javascript)

Please note that wp_ is Site A‘s table prefix. If yours is different you need update these lines.

Great job, both sites are now sharing the same users (if you did everything right).

Share Login Cookies

Now that both websites are using the same login details, you will notice that if you switch websites you will have to log in again. That can be fixed by sharing login cookies, here’s how to do it.

1. Edit Site A’s wp-config.php

Right before /* That’s all, stop editing! Happy blogging. */, add the following lines:

define( 'COOKIE_DOMAIN', '' ); define( 'COOKIEHASH', md5( '' ) ); /* That's all, stop editing! Happy blogging. */
Code language: JavaScript (javascript)

In the first line, you will have to replace with your actual domain. In the second line, you have to put your WordPress Site Address (URL), which you can get from Dashboard -> Settings -> General

Don’t close Site A‘s wp-config.php yet, we’ll still need some info for Site B.

2. Edit Site B’s wp-config.php

Similar to how we did for the database name, user and password, we will now copy the following lines from Site A and replace those existing in Site B:

define('AUTH_KEY', 'stringof40characters'); define('SECURE_AUTH_KEY', 'stringof40characters'); define('LOGGED_IN_KEY', 'stringof40characters'); define('NONCE_KEY', 'stringof40characters'); define('AUTH_SALT', 'stringof40characters'); define('SECURE_AUTH_SALT', 'stringof40characters'); define('LOGGED_IN_SALT', 'stringof40characters'); define('NONCE_SALT', 'stringof40characters');
Code language: JavaScript (javascript)

Obviously, you won’t actually find anything in there names stringof40characters, but some different random strings of 40 characters.
Next, we need to make sure Site B is sharing login cookies with Site A.

Similar to the previous step we will now edit Site B‘s wp-config.php and add the same lines we added for Site A.

define( 'COOKIE_DOMAIN', '' ); define( 'COOKIEHASH', md5( '' ) ); /* That's all, stop editing! Happy blogging. */
Code language: JavaScript (javascript)

Get Administrator rights on your second site (Site B)

After you’ve done the steps above, you will notice that your websites are indeed synchronizing login sessions, but you are not allowed to access the admin dashboard.
You will be greeted with this error message: Sorry, you are not allowed to access this page.

To gain access to it, we’ll need to manually edit wp_usermeta database table. There’s plenty of options to do this, most of you will have phpMyAdmin installed on your server. Personally, I’m using Adminer (a.k.a. phpMinAdmin) because I rarely ever edit the database and I don’t need it permanently installed.

Next, open your Database and go to the wp_usermeta table. If you’re using Adminer too, you’ll have to click Select data to find out wp_capabilities meta_key.

Copy the meta_value from wp_capabilities of your admin user, create a New item and set:

  • umeta_id (leave it blank, it will auto increment)
  • user_id: 1 (for most of you, 1 will be user_id of the administrator on Site A)
  • meta_key: com_capabilities (com_ is the prefix for Site B. Replace it with your prefix)
  • meta_value: Copy-paste the same meta_value from wp_capabilities for user_id = 1

When done, it should look like this.

And now you’re done! Your websites are¬†sharing users, logins and you’ve given yourself Administrator user role on site B too.