Skip to content

Instantly share code, notes, and snippets.

@StoyPenny
Last active December 4, 2021 18:01
Show Gist options
  • Save StoyPenny/9ae653cea18ae730b35c7f8e7e483ab5 to your computer and use it in GitHub Desktop.
Save StoyPenny/9ae653cea18ae730b35c7f8e7e483ab5 to your computer and use it in GitHub Desktop.
WordPress Configuration

Set Number of Post Revisions

WordPress comes with the ability to automatically store post revisions so that you have a complete timeline of edits for every post/page on your website. This can lead to massive bloat in your database over time. By default WordPress does not impose a limit on the number of revisions that your website will store, but you can set a custom limit with the following function.

define( 'WP_POST_REVISIONS', 2 );      // Set the number of post revisions to 2
define( 'WP_POST_REVISIONS', false );  // Disable post revisions

Set Autosave Interval

WordPress provides an autosave feature by default to ensure that you don't lose any/much content in the case of a technical incident. By default, WordPress will autosave a post/page every 60 seconds, you can control when this happens with the following function.

define( 'AUTOSAVE_INTERVAL', 180 ); // Set autosave to happen every 180 Seconds

Set Trash Takeout

When you delete a post/page, WordPress will keep that page in the trash for 30 days before completely removing the information from the database. You can set a custom interval to clear the trash on your website with the following function.

define( 'EMPTY_TRASH_DAYS', 5 ); // 5 days

Set Debug

WordPress has several debugging options available. For development websites, its safe to turn on the normal Debug. For production websites, please use the Debug Log as to not show errors to visitors on the live site.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );

Set URL

Set the site URL for your website define( 'WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/path/to/wordpress' ); define( 'WP_HOME', 'http://example.com' );

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

Move WP Content Folder

Change the location of the default WP Content folder for your WordPress installation.

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/blog/wp-content' );

Set Cookie Domain

Change the domain for your cookies, this can be useful for non-common URL setups like subdomains with static assets coming from the primary website.

define( 'COOKIE_DOMAIN', 'www.example.com' );

Control Memory Limit

You can alter the amount of PHP memory that WordPress will use.

define( 'WP_MEMORY_LIMIT', '64M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Used for large admin scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment