Posted on

Can 2 WordPress Websites Share 1 WP-Content Folder?


There are a number of benefits to sharing the WordPress content folder; Both websites will have access to the same themes and plugins. This means that both sites could use a single theme, allowing an easily manageable identical look for two domain names. Media files are saved to the same location, but appear separate in WP. This makes backing up easier.

To accomplish this you need to rearrange things and create symbolic links that go from the old wp-content location to the new shared location. Because I like you, I wrote this quick PHP script to make it easy for you. Simply update the $folderA and $folderB variables to whatever your names are. Then upload the file to your website and run the script in your browser: Then delete the file once you are done.

Download the Script

<?php // This script creates two symbolic links that allow two WordPress sites to share one common wp-content folder
// Rev 07-06-17
error_reporting (E_ALL);
ini_set ('display_errors', TRUE);
// Website A folder name
$folderA = 'mywebsitefolder'; // Existing Website

// Website B folder name
$folderB = 'newsitefolder'; // New website to share content

// Shared content folder name
$content = 'wp-content'; // (at same level as website folders)

// Build paths
$websiteA = $_SERVER['DOCUMENT_ROOT'] . '/' . $folderA;
$contentA = $websiteA . '/wp-content';

$websiteB = $_SERVER['DOCUMENT_ROOT'] . '/' . $folderB;
$contentB = $websiteB . '/wp-content';

$contentShared = $_SERVER['DOCUMENT_ROOT'] . '/' . $content;

// Check if the paths are good...
if( is_dir($contentA) AND is_dir($contentB) ) { //
 // Rename the original wp-content folder
 $contentB_Saved = $contentB . '_SAVED';
 if(!rename($contentB , $contentB_Saved) ) { exit('Error: Website B wp-content could not be renamed. Aborting...'); }
 // Move WebsiteA's wp-content to root
 if(rename($contentA , $contentShared)) {
 // Make the symlinks
 if(symlink($contentShared, $contentA)) {
 echo "<p>Symlink A Created: $contentA<br />---&gt; $contentShared</p>";
 if(symlink($contentShared, $contentB)) {
 echo "<p>Symlink B Created: $contentB<br />---&gt; $contentShared</p>";
 echo '<p>' . readlink($contentShared) . '</p>';
 exit('Success :-) ');
 } else {
 exit('Symlink B Could Not Be Created :-(');
 } else {
 exit('Symlink A Could Not Be Created :-(');
 } else {
 exit('wp-content could not be copied to root :-(');
} else {
 exit('Directory Read Error :-( ' . $contentB);