Skip to content

Instantly share code, notes, and snippets.

@Lukas238
Last active November 23, 2017 13:40
Show Gist options
  • Save Lukas238/4451e3fc74993daa03e1 to your computer and use it in GitHub Desktop.
Save Lukas238/4451e3fc74993daa03e1 to your computer and use it in GitHub Desktop.
Multi-Environment Config Part for Wordpress

Multi-Environment Config Part for Wordpress

1. Include this code in the wp-config.php file.

/*
* 	Multi-Environment Config part for WordPress
*	By [email protected]
*
* Determines the current domain hosting, and calls
* the corresponding configuration file, defined by
* the "WP_ENV" constant.
*
* Ex.: Config file part name => config.[WP_ENV].php
*
*/
define('HOSTNAME', $_SERVER['SERVER_NAME']);
 
switch (HOSTNAME) {
	case 'stage.mytestsite.local':
		define('WP_ENV', 'stage');
        break;
		
	//case 'dev.mytestsite.local':
	default: 
		define('WP_ENV', 'dev');
        break;
} 
include_once('wp-config.'. WP_ENV .'.php');

2.Config part file example (config.[WP_ENV].php)

DEV config part

File name: config.dev.php

<?php
/*  DEV  */ 
define('DB_NAME', 'mydatabasename');
define('DB_USER', 'mysqluser');
define('DB_PASSWORD', 'mysqlpassword');
define('DB_HOST', 'mydatabasehost');

define('WP_SITEURL', 'http://dev.mytestsite.local/');
define('WP_HOME', WP_SITEURL);

STAGE config part

File name: config.stage.php

<?php
/*  STAGE  */ 
define('DB_NAME', 'mydatabasename');
define('DB_USER', 'mysqluser');
define('DB_PASSWORD', 'mysqlpassword');
define('DB_HOST', 'mydatabasehost');

define('WP_SITEURL', 'http://stage.mytestsite.local/');
define('WP_HOME', WP_SITEURL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment