15 wp-config Snippets to Configure WordPress Site – Netadroit WebDesign
WordPress admin makes it simple to handle configurations with out touching a line of code. These fundamental configuration settings are then saved within the
wp-choices desk contained in the database. But, WordPress additionally has a separate configuration file, referred to as
wp-config.php, that can be utilized for additional customizations.
Wp-config is the file the place your customized internet hosting knowledge (database title, database host, and so on.) is saved once you set up a self-hosted WordPress web site. You may also add different configuration choices to this file, with which you’ll allow or disable options akin to debugging, cache, multisite, SSL login, automated updates, and lots of others.
Read Also: 15 Useful .htaccess Snippets for Your WordPress Site
Localize and edit wp-config
When you obtain WordPress, the
wp-config.php file is not but current contained in the set up folder. However, there’s a file referred to as
wp-config-sample.php that you simply want to copy and rename to
wp-config.php. Then, you want to add your fundamental connection knowledge (database title, database username, database password, hostname, safety keys) to this file.
If your internet hosting supplier makes use of the Softaculous auto installer (most accomplish that) this course of is automated for you and you will discover a
wp-config.php and a
wp-config-sample.php file in your root folder once you join your server through FTP.
Note that the order of settings issues, so don’t rearrange them. When enhancing the wp-config file, all the time use a code editor akin to Sublime Text, Atom, Notepad++, Visual Studio Code, or TextMate. Word processors (Microsoft Office, Google Docs, LibreOffice, and so on.) will mess your file up, by no means use them to edit code recordsdata.
The settings saved into wp-config override the database, in case the identical sort of configuration is current at each (e.g. house URL)
Where to place the code snippets
In this text, you’ll find 20 code snippets with which you need to use to customise your
Most of those configuration choices don’t exist in wp-config by default. If you need to use them you want to add them beneath the beginning
<?php tag and code feedback, however above the MySQL settings.
1. Turn on WP debugger
You can flip the WordPress debugger on and off within the wp-config file. The first snippet beneath does exist by default in wp-config (beneath the database configurations) however its worth is ready to
false. To flip the debugger on, change its worth to
2. Change database desk prefix
WordPress makes use of the
wp_ desk prefix by default. If you need a safer database you may select a extra sophisticated desk prefix.
This config choice additionally exists within the wp-config file by default, you solely want to change the worth of the
$table_prefix variable to a safer one.
Only change the desk prefix you probably have a clear set up or on a growth web site, because it’s dangerous to accomplish that on a manufacturing web site.
# Creates safe desk prefix for database tables # Only numbers, letters, underscores $table_prefix = 'a81kJt_';
3. Change WordPress URLs
You can set the WordPress and residential URLs within the WordPress admin, underneath the
Settings > General menu. However, you can too configure these URLs within the wp-config file.
WP_HOME constants within the wp-config file has two benefits:
- it may be life-saving should you can’t entry your admin space for some purpose
- it could actually scale back the variety of database calls whereas your web site is loading (as wp-config overrides the choices saved within the database)
WP_SITEURL specifies the URL customers can attain your web site with, whereas
WP_HOME defines the root of your WP set up. If you put in WordPress into your root folder (that is the default choice) they take the identical worth.
# Specifies web site URL outline('WP_SITEURL', 'http://www.yourwebsite.com'); # Specifies house URL (the foundation of the WP set up) outline('WP_HOME', 'http://www.yourwebsite.com/wordpress');
4. Empty trash after a sure time
You could make WordPress to routinely empty your trash after a sure variety of dates. The smallest worth of this fixed is 0, on this case you disable the trash function.
# Empties trash after 7 days outline( 'EMPTY_TRASH_DAYS', 7 );
5. Enable WordPress cache
You can allow WordPress’ constructed-in caching function with the next line of code. Most caching plugins, akin to W3 Total Cache and WP Super Cache, routinely add this snippet to the wp-config file.
# Enables WP cache outline( 'WP_CACHE', true );
6. Enable WordPress Multisite
By including the
WP_ALLOW_MULTISITE fixed to your wp-config file, you may allow WordPress’ multisite function that permits you to create a community of WP websites.
# Turns on WordPress Multisite outline( 'WP_ALLOW_MULTISITE', true );
7. Redirect non-current subdomains and subfolders
Sometimes guests sort a non-current subdomain or subfolder into the URL bar. You can redirect these customers to one other web page in your area, for example to the homepage with the assistance of the
# Redirects non-current subdomains and subfolders to homepage outline( 'NOBLOGREDIRECT', 'http://www.yourwebsite.com' );
8. Manage submit revisions
WordPress has a constructed-in model management system, which implies it saves all submit revisions you create. A continuously edited submit can have as many as 25-30 revisions that may take up lots of database area after some time.
WP_POST_REVISIONS fixed, you may maximize the variety of submit revisions or fully disable the function.
# Completely disables submit revisions outline( 'WP_POST_REVISIONS', false ); # Allows most 5 submit revisions outline( 'WP_POST_REVISIONS', 5 );
9. Enable constructed-in database optimization
WordPress has a constructed-in database optimization function you may activate by including the next line to the wp-config file.
I wrote intimately about how this tool works on this article. The most necessary factor to word is that the database optimization display screen is accessible for anybody (even for non-logged in guests). Enable the function just for the time frame you need to run the optimization tool, then don’t neglect to disable it.
# Turns on database optimization function outline( 'WP_ALLOW_REPAIR', true );
10. Disable automated updates
WordPress runs automated background updates by default for minor releases and translation recordsdata.
You can toggle this function on and off by setting the values of the
AUTOMATIC_UPDATER_DISABLED (for all updates) and
WP_AUTO_UPDATE_CORE (for core updates) constants in accordance to the next guidelines:
# Disables all automated updates outline( 'AUTOMATIC_UPDATER_DISABLED', true ); # Disables all core updates outline( 'WP_AUTO_UPDATE_CORE', false ); # Enables all core updates, together with minor and main releases outline( 'WP_AUTO_UPDATE_CORE', true ); # Enables core updates just for minor releases (default) outline( 'WP_AUTO_UPDATE_CORE', 'minor' );
11. Increase PHP reminiscence restrict
Sometimes it’s your decision to improve the PHP reminiscence restrict your internet hosting supplier has allotted to your web site, particularly should you get the dreaded “Allowed memory size of xxxxxx bytes exhausted” message. To accomplish that, use
WP_MEMORY_LIMIT for the website and
WP_MAX_MEMORY_LIMIT for the admin space.
Note that some hosts don’t permit to improve the reminiscence restrict manually, on this case contact them and ask them to do it for you.
# Sets reminiscence restrict for the website outline( 'WP_MEMORY_LIMIT', '96M' ); # Sets reminiscence restrict for the admin space outline( 'WP_MAX_MEMORY_LIMIT', '128M' );
12. Force SSL login
To improve website safety, you may drive customers to log in by way of SSL each time. The
FORCE_SSL_ADMIN fixed makes SSL obligatory for each person logins and admin periods.
Note that the previously legitimate
FORCE_SSL_LOGIN fixed was deprecated in WordPress 4.0, so now you all the time have to use
# Forces SSL login outline( 'FORCE_SSL_ADMIN', true );
13. Disable plugin and theme edits / updates
Administrators can edit plugin and theme recordsdata within the WordPress admin space. You could make your web site safer should you disable the plugin and theme editors utilizing the
DISALLOW_FILE_EDIT fixed. So, in case your web site is hacked the hacker received’t have entry to your plugin and theme recordsdata.
You may also disable the plugin and theme replace function utilizing
DISALLOW_FILE_MODS. This approach directors received’t have the option to replace plugins and themes within the admin space.
DISALLOW_FILE_MODS additionally disables the plugin and theme editor, so should you use it you don’t have to add
# Disables the plugin and theme editor outline( 'DISALLOW_FILE_EDIT', true ); # Disables the plugin & theme editor PLUS the plugin & theme replace outline( 'DISALLOW_FILE_MODS', true );
14. Delete picture edits
Whenever you edit a picture, WordPress saves it in numerous resolutions. But, should you don’t need to use the sooner units of photographs you may take away them by setting the worth of the
IMAGE_EDIT_OVERWRITE fixed to
As a end result, the sooner picture recordsdata can be overwritten by the brand new ones once you edit a picture and solely the final set can be saved within the
wp-content material folder.
# Cleans up picture edits outline( 'IMAGE_EDIT_OVERWRITE', true );
15. Disable unfiltered HTML
Although low-degree customers (subscribers, contributors, authors) can’t publish unfiltered HTML in WordPress, editors and directors are allowed to accomplish that.
By including the next line of code to your wp-config file, you may improve safety by stopping excessive-degree customers from publishing unfiltered HTML.
# Disables unfiltered HTML for admins and editors outline( 'DISALLOW_UNFILTERED_HTML', true );
Read Also: 5 Tips to Toughen Up Your WordPress Login Security