Manage Multiple WordPress Sites With One Database and One Code Base


/ Published in: PHP
Save to your folder(s)

This is a simple but powerful tweak to the wp-config.php file that will make it easy to run multiple websites using one database and codebase. Simply change "yourdomain.com" with your domain and that's it. Repeat that line for new domains.


Copy this code and paste it in your HTML
  1. // You can have multiple installations in one database if you give each a unique prefix
  2.  
  3. $domain_list = array();
  4.  
  5. // auto database name
  6. $domain_list["yourdomain.com"] = "";\
  7.  
  8. $domain_name = preg_replace("/^www\./", "", $_SERVER["SERVER_NAME"]);
  9.  
  10. if (array_key_exists($domain_name, $domain_list))
  11. {
  12. $table_prefix = $domain_list[$domain_name];
  13. if (!$table_prefix) { $table_prefix = "wp_" . md5($domain_name); }
  14. }
  15. else
  16. {
  17. print "Unknown error"; exit;
  18. }

URL: http://sitening.com/blog/how-to-easily-manage-multiple-wordpress-sites-with-one-database-and-one-code-base/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.