Skip to content

Instantly share code, notes, and snippets.

@WolfieZero
Last active December 25, 2015 06:49
Show Gist options
  • Save WolfieZero/6934694 to your computer and use it in GitHub Desktop.
Save WolfieZero/6934694 to your computer and use it in GitHub Desktop.
Editing the wp-config.php file to load in another file if available. Makes working across multiple environments easier. Bonus tip; set your live site in wp-config.php and all other locations in wp-config-local.php. I also install WP in it's own directory making it easier to use git submodules.
<?php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '...');
/** MySQL database username */
define('DB_USER', '...');
/** MySQL database password */
define('DB_PASSWORD', '...');
/** MySQL hostname */
define('DB_HOST', '127.0.0.1');
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*/
define('WP_DEBUG', true);
/**
* Server name
*
* The domain overwrite for WordPress. By default set automatically but can be
* written here.
*/
define('WP_SERVER_NAME', $_SERVER['HTTP_HOST']);
/**
* Dev Site
*
* We can tell the code this is a dev site and thus write certain conditions
* for this.
*/
define('WP_DEV', true);
<?php
// ...
/**
* Check for wp-config-local.php
*
* If there is a local-config.php file then we use that to over-write settings
* make in this file with those in the dev file. Keep in mind that this should
* be overwritten for dev and the live settings should stay here (unless you
* are security paranoid).
*/
if( file_exists( dirname( __FILE__ ) . '/wp-config-local.php' ) ) {
include( dirname( __FILE__ ) . '/wp-config-local.php' );
} else {
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '...');
/** MySQL database username */
define('DB_USER', '...');
/** MySQL database password */
define('DB_PASSWORD', '...');
/** MySQL hostname */
define('DB_HOST', '...');
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*/
define('WP_DEBUG', false);
/**
* Server name
*
* The domain overwrite for WordPress. By default set automatically but can be
* written here.
*/
define('WP_SERVER_NAME', $_SERVER['HTTP_HOST']);
/**
* Dev Site
*
* We can tell the code this is a dev site and thus write certain conditions
* for this.
*/
define('WP_DEV', false);
}
// ...
/**
* Set custom paths
*
* These are required because wordpress is installed in a subdirectory.
*/
define('WP_SITEURL', 'http://' . WP_SERVER_NAME . '/wp');
define('WP_HOME', 'http://' . WP_SERVER_NAME . '');
define('WP_CONTENT_DIR', __dir__ . '/content');
define('WP_CONTENT_URL', 'http://' . WP_SERVER_NAME . '/content');
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment