Skip to content

Instantly share code, notes, and snippets.

@lunule
Last active April 17, 2024 15:18
Show Gist options
  • Save lunule/38f34a87c9f8123596857df6dc22eea3 to your computer and use it in GitHub Desktop.
Save lunule/38f34a87c9f8123596857df6dc22eea3 to your computer and use it in GitHub Desktop.
[WordPress - wp-config.php Tips 'N' Tricks] #collection #bestof #config #wp-config #wp #core
<?php
/**
* WordPress Localized Language, defaults to English.
*
* Change this to localize WordPress. A corresponding MO file for the chosen
* language must be installed to wp-content/languages. For example, install
* de.mo to wp-content/languages and set WPLANG to 'de' to enable German
* language support.
*/
// ------------------------------------------------------------------------------------------------
define ('WPLANG', '');
// Performance
// ------------------------------------------------------------------------------------------------
define( 'WP_MEMORY_LIMIT', '2048M'); // Increase memory limit
define( 'WP_MAX_MEMORY_LIMIT', '4096M' ); // Increase max memory limit
define( 'EMPTY_TRASH_DAYS', 15 ); // Empty trash after X days
define( 'WP_POST_REVISIONS', 50 ); // Limit the number of saved revisions
define( 'WP_POST_REVISIONS', false ); // Disable revisions
define( 'WP_POST_REVISIONS', 5 ); // Limit revisions to 5
define( 'AUTOSAVE_INTERVAL', 120 ); // Change autosave interval to 120 seconds
// Set execution time
set_time_limit(300);
// Enable multisite
// ------------------------------------------------------------------------------------------------
define( 'WP_ALLOW_MULTISITE', true );
// Updates
// ------------------------------------------------------------------------------------------------
define( 'AUTOMATIC_UPDATER_DISABLED', true ); // Disable all automatic updates
define( 'WP_AUTO_UPDATE_CORE', false ); // Disable automatic updates for core
add_filter( 'auto_update_theme', '__return_false' ); // Disable automatic updates for themes
add_filter( 'auto_update_plugin', '__return_false' ); // Disable automatic updates for plugins
// Configure WP environment
// ------------------------------------------------------------------------------------------------
define( 'WP_ENVIRONMENT_TYPE', 'production' );
// Change/define site url
// ------------------------------------------------------------------------------------------------
define( 'WP_HOME', 'http://example.com' ); // no trailing slash!!!
define( 'WP_SITEURL', 'http://example.com' ); // no trailing slash!!!
// Change WP-CONTENT folder PATH and URL
// ------------------------------------------------------------------------------------------------
// Make sure the ABSPATH constant is available
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
// FYKI - OPTIONAL!!! - only required if you choose version 1 from the following sub-sections!!
define( 'WP_CONTENT_FOLDERNAME', 'foo-content' );
// TWO VERSIONS OF THE SAME THING
define( 'WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/foo-content' );
// TWO VERSIONS OF THE SAME THING
define( 'WP_CONTENT_URL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . WP_CONTENT_FOLDERNAME );
define( 'WP_CONTENT_URL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/foo-content' );
// Change PLUGINS folder PATH and URL
// ------------------------------------------------------------------------------------------------
// Make sure the ABSPATH constant is available
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
// FYKI - OPTIONAL!!! - only required if you choose version 1 from the following sub-sections!!
define( 'WP_PLUGIN_FOLDERNAME', 'add-ons' );
// TWO VERSIONS OF THE SAME THING
define( 'WP_PLUGIN_DIR', ABSPATH . WP_CONTENT_FOLDERNAME . '/' . WP_PLUGIN_FOLDERNAME );
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/foo-content/add-ons' );
// TWO VERSIONS OF THE SAME THING
define( 'WP_PLUGIN_URL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . WP_CONTENT_FOLDERNAME . '/' . WP_PLUGIN_FOLDERNAME );
define( 'WP_PLUGIN_URL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/foo-content/add-ons' );
// Change UPLOADS folder PATH
// ------------------------------------------------------------------------------------------------
// Change uploads folder name and location
define( 'UPLOADS', 'foo-content/add-ons' );
// Set custom default theme
// ------------------------------------------------------------------------------------------------
define( 'WP_DEFAULT_THEME', 'mytheme' );
// Debug Log
// ------------------------------------------------------------------------------------------------
define( 'WP_DEBUG', true ); // Turn on debugging mode in WordPress
define( 'WP_DEBUG_LOG', true ); // Log debugging information to a file
define( 'WP_DEBUG_DISPLAY', false ); // Hide debugging information from being displayed on
// the site
define( 'SCRIPT_DEBUG', true ); // loads the development (non-minified) versions of all
// scripts and CSS, and disables compression and
// concatenation.
// Error Log
// ------------------------------------------------------------------------------------------------
@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/path/domain/logs/php_error.log');
// Disable plugin/theme fatal error emails
// ------------------------------------------------------------------------------------------------
/**
* WordPress 5.2 introduced a fatal error handler to ensure that users do not get locked
* out of their site when a theme or plugin causes a fatal error. This is a great feature
* in production/live sites.
*
* But IT CAN BE PROBLEMATIC IN DEVELOPMENT, preventing you from fully diagnosing errors.
*
* For this reason, IN DEVELOPMENT, YOU SHOULD DISABLE THIS (SET IT TO `TRUE`) to make
* sure things are broken until you can fix them.
*
* Define this constant in your wp-config.php file:
*/
define('WP_DISABLE_FATAL_ERROR_HANDLER', true);
// Controlling core wp script concatenation and minification
// ------------------------------------------------------------------------------------------------
define( 'CONCATENATE_SCRIPTS', true );
define( 'COMPRESS_SCRIPTS', true );
define( 'COMPRESS_CSS', true );
define( 'ENFORCE_GZIP', true ); //forces gzip for compression instead of deflate
// Logging SQL queries
// ------------------------------------------------------------------------------------------------
define( 'SAVEQUERIES', true );
global $wpdb;
print_r( $wpdb->queries );
// Database
// ------------------------------------------------------------------------------------------------
define( 'CUSTOM_USER_TABLE', $table_prefix . 'my_users' ); // Use my_users instead of
// wp_users
define( 'CUSTOM_USER_META_TABLE', $table_prefix . 'my_usermeta' ); // Use my_usermeta instead of
// wp_usermeta
define( 'DB_COLLATE', 'utf8mb4_unicode_ci' ); // Database collation
// Enable DB repair
// Usage: after saving wp-config.php, update the wp-admin slug: /wp-admin/maint/repair.php
define( 'WP_ALLOW_REPAIR', true );
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Disable table updates
// Security
define( 'DISALLOW_FILE_EDIT', true ); // Disable admin theme and
// plugin editors
define( 'WP_HTTP_BLOCK_EXTERNAL', true ); // Blocking External HTTP
// Requests
define( 'WP_ACCESSIBLE_HOSTS', 'api.wordpress.org,*.github.com' ); // Allow specific external
// HTTP requests
define( 'FORCE_SSL_ADMIN', true ); // Forcing SSL for Login Pages
// and the Dashboard
/**
* @ini_set methods - alternatively, you can try updating the values in the .htaccess, or a
* custom php.ini file in the wp root, but usually, if the below updates
* in wp-config.php don't work, they won't work in other files either,
* meaning the values should be updated directly in the hosting panel.
*/
// ------------------------------------------------------------------------------------------------
// Upload size
@ini_set( 'upload_max_filesize' , '2048M' );
@ini_set( 'post_max_size', '2048M');
// Execution & Input Time
@ini_set( 'max_execution_time', '300' );
@ini_set( 'max_input_time', '300' );
// Memory limit
@ini_set( 'memory_limit', '4096M' ); // CAREFUL!!! There's DEFINE version for this one:
// define( 'WP_MEMORY_LIMIT', '2048M');
// see in PERFORMANCE subsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment