WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress configuration tricks

287

Some pipin’ hot WordPress configuration tricks for the wp-config.php file. All snippets strictly plug-&-play, no fiddling required. I use most of these on my own sites, so thought I would share ’em here at WP-Mix.

Toggle error log

This snippet saves a few keystrokes when enabling error logging:

define('WP_DEBUG', true);

if (WP_DEBUG) {
	define('WP_DEBUG_LOG', true);
} else {
	define('WP_DEBUG_LOG', false);
}

So you just change true or false one time as needed, and then let the conditional logic do the work. You can also add other error-logging constants to the mix, for example:

define('WP_DEBUG_DISPLAY', false);
define('SAVEQUERIES',      false);

Over time, a few seconds add up to minutes add up to hours..

Control Admin Area

Here are a set of constants that I use to fine-tune the functionality of the WordPress Admin Area:

define('DISALLOW_FILE_EDIT',  true);
define('WP_AUTO_UPDATE_CORE', false);
define('WP_POST_REVISIONS',   true);
define('WP_PAGE_REVISIONS',   true);
define('EMPTY_TRASH_DAYS',    999);

In order, these definitions control file editing (for both plugins and themes), auto-updates of the WP core, post revisions, page revisions, and the interval for auto-emptying of the trash bin.

As a bonus, here are constants for setting the default theme and disabling auto-updates for bundled plugins and themes (anything in the /wp-content/ directory):

define('WP_DEFAULT_THEME', 'theme-folder-name');
define('CORE_UPGRADE_SKIP_NEW_BUNDLED', true);

The skip-new-bundled definition is nice because it stops WordPress from re-adding the default plugins and themes for every major upgrade. So if you don’t use the default plugins and themes, you don’t have to keep deleting them over and over and over..

Set site URLs

Last but not least, the constants for setting the Site URL and Home URL for your WordPress site:

define('WP_SITEURL', 'http://example.com/wp');
define('WP_HOME',    'http://example.com');

These override the General settings, Site URL and Home URL, respectively. Note that you should NOT include any trailing slash on either URL.

Go deeper with wp-config

To go even further with customizing the WordPress configuration file, check out these fine tutorials over at Digging Into WordPress:

Also may want to check out some related wp-config tutorials here at WP-Mix.

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!