How to Customize the WordPress wp-config File

As we already know how important is the WordPress wp-config.php file. It has all the info regarding the databases used in a website. The file also has the security keys and passwords for the site. Now you may question whether we can customize the wp-config..? The customization part will happen only when we edit the wp-config. While editing you will have to be careful. Otherwise, a wrong piece of code will render your website non-functional.

So, in this post, we will see how to customize the WordPress wp-config file. By customizing we mean to personalize the URLs, directory locations. adding custom themes, custom database tables. In our previous posts, We have also mentioned in details about the wp-config.php file. We have linked it below. So, check it out.

What is WordPress wp-config.php: A Detailed Insight

How to Customize the WordPress wp-config File

Now, we will see the various elements of the file which we can customize.

WordPress URLs

The URLs in WordPress has two Settings. They are WP_SiteURL and WP_Home

The first URL refers to WP_SITEURL and the second one refers to WP_HOME. SiteURL will point the users to your website and Site address points to the root of your WordPress package installed on the system. If we use the config file to define the URLs, Admin’s Settings will be overwritten and the config file will take precedence.

Custom Directory Locations

With the wp-config file, you can modify the location of various folders of WordPress. The modification will allow you to move the content, plugins, upload directories. Additionally, it will also enable you to create these directories.

The config file allows you to modify the location of various folders used by WordPress. You can move the content, plugins and uploads directories and create additional theme directories using the method outlined below. The reason why we may want to modify anything is to imitate a folder structure when we a site migration is in action from one system to another. Also, you can do it to clear out junk from the root directory.

here you can have a look at the tweak.

// Moving the wp-content directory
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/extensions' );
define( 'WP_CONTENT_URL', 'http://mywebsite.com/extensions' );

// Moving the plugins directory
define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/extensions/plugins' );
define( 'WP_PLUGIN_URL', 'http://mywebsite.com/extensions/plugins' );
define( 'PLUGINDIR', dirname(__FILE__) . '/extensions/plugins' );

// Creating an additional theme directory
register_theme_directory( dirname( __FILE__ ) . '/themes-dev' );

// Moving the uploads directory
define( 'UPLOADS', 'uploads' );

Different folders and directories behave differently. For instance, the wp-content requires an absolute path and full URI. However, if we look at the plugins directory, it makes use of the plugindir.

The default theme directory is always set to the directory named themes inside the content directory. You can, however, add additional theme directories. Take a look at the code above to understand.

Again, the uploads directory is relative to the ABSPATH directory which will be the root directory. There is a special category of Plugins called Must-use Plugins. These are loaded by default before any other plugin loads.

You can change the location of the plugins with this piece of code.

define( 'WPMU_PLUGIN_DIR', dirname(__FILE__) . '/extensions/builtin' );
define( 'WPMU_PLUGIN_URL', 'http://mywebsite.com/extensions/builtin' ); 

Custom Default Theme

if you are the one who is interested in trying out various themes, then you can change the WP_Deafult_Theme to your preferred theme’s folder name. This can be the code for it.

define('WP_DEFAULT_THEME', 'twentyeleven');

In case there is some issue with your theme which you applied, your site will revert back to the original default theme.

Custom Database Tables

WordPress can provide different user names for user tables and user meta tables. Custom tables are secure but anyone having access to your database will figure this out.

define( 'CUSTOM_USER_TABLE', $table_prefix.'peeps' );
define( 'CUSTOM_USER_META_TABLE', $table_prefix.'peepmeta' );

Revisions and Autosaves

WordPress allows the user to limit or disable revisions using the WP_POST_REVISIONS constant.

// Disable post revisions
define( 'WP_POST_REVISIONS', false );

// Limit revisions to 4
define( 'WP_POST_REVISIONS', 4 );

Keep in mind that you have to use any one of both codes put up above.

Now coming to the autosave part, by default WordPress saves your post every 1 minute. However, the user can increase the autosave time. Here is how you can do it.

define( 'AUTOSAVE_INTERVAL', 120 );

Trash

To enable an efficient clutter control, you can control how many days a post can stay in the trash before it is completely deleted. You can set it up by,

define( 'EMPTY_TRASH_DAYS', 3 );

Increasing the Memory Limit

Sooner or later there will be the need to allocate more memory. To set the memory limit, you can make use of by this piece of code.

define( 'WP_MEMORY_LIMIT', '32M' );
define( 'WP_MAX_MEMORY_LIMIT', '128M' ); 

How to Disbale Table Updates

When WordPress updates it makes use of a function called dbDelta() to integrate the changes made.

define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true );

Many larger websites themselves disable the table updates to integrate the changes themselves when the traffic is low. This is because the integration of changes will take a lot of time on these sites.

SSL in the Admin

There are two attributes of SSL in the wp-config file. First, the FORCE_SSL_LOGIN ensures that logins always use SSL. However, but the admin sessions don’t make use of it. The second one is the FORCE_SSL_ADMIN, which will use SSL for login and will also include the cookies.

define( 'FORCE_SSL_LOGIN', true );
define( 'FORCE_SSL_ADMIN', true );

SSL Admin overrides the SSL Login so if you have defined a secure option then there is no need for defining Force_SSL_Login.

Disabling the Automatic Updates

Almost everyone loves the hassle-free automatic updates where all updates download on their own and integrate. WordPress is no exception to that. You can, however, disable the automatic updates on WordPress. There are two ways to do that.

You can make use of AUTOMATIC_UPDATER_DISABLED can disable all automatic updates in one go. A better way to do this is to use the WP_AUTO_UPDATE_CORE constant.

With the second one, if you set the auto-update core to true, the auto-update will be enabled. If you set it to False, it will be disabled. You can set it to minor to receive smaller updates automatically by default.

Cron Settings

The Cron is a job scheduler of mostly found in the UNIX based systems. WordPress has similar functionality with the same attributes as the Cron. It runs at regular intervals and executes various tasks. the problem with the functionality is it relies upon site visitors to perform a task. So, the desired task may not be finished at the stipulated time.

If you’ve set a post to be published at 12 AM and you have no visitor on the site until the stipulated time. then the post will be published before the site loads for the user. However, in case, due to some unforeseen issue it fluctuates, you can set up another alternate cron method. Here is the piece of code for that.

define( 'ALTERNATE_WP_CRON', true );

WordPress Multi-site

A multisite network basically refers to an accumulation of websites that share the same WordPress install. They can share plugins and themes. In this scheme managing of sites is easier. Developers use this concept to host multiple themes and plugins.

This is the code to set up the multi-site. You have to set the parameter value to true.

define( 'WP_ALLOW_MULTISITE', true );

After you define it, upon reloading the WordPress admin, you will see a Network Setup option in the tools section. You will be asked to add your additional settings to your config files and .htaccess file. Then you have to log out and log in again. Then you’ll see the network install.

A setting related to Multisite installs allows you to redirect users by using The NOBLOGREDIRECT constant defines the URL users are directed to in case they access a sub-site, which does not exist.

define( 'NOBLOGREDIRECT', 'http://mainwebsite.com' );

In case you want that plugins and themes cannot be edited using the built-in file editor or want that users can’t install their own plugins and themes, you can use the DISALLOW_FILE_EDIT and DISALLOW_FILE_MODS constant.

define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', true );

Developer Settings

There is a Debug constant which the developers can use to show the errors so they can rectify it. here is the code for it.

define( 'SCRIPT_DEBUG', true );

debugging is very much dependent on how much error is logged in the log files. So, logging down the errors is always a good practice. So, to define the log you can make use of this following code.

define( 'WP_DEBUG_LOG', true );

Then the errors will be logged to a file named error.log in the wp-content folder.

Again if you want to trace some bugs in any script that your site is running, you have to use the Concatenation and Minification constants.

To access detailed profiles of the SQL queries performed by WordPress, you can use this code.

define( 'SAVEQUERIES', true );

Now to get the overview of all the queries, you have to print the content of $wpdb->queries. So, make use of this,

global $wpdb;
print_r( $wpdb->queries );

.

If you want to see these queries all the time, then you can put it into the wp_footer file. They will display at the end of each page.

So, that’s it, folks. Now you know how to Customize the WordPress wp-config File. We hope this guide was useful to you.

2019-05-16T13:24:27+00:00

About the Author:

Leave A Comment