15 Configuration Hacks That Every WordPress Developer Should Know
Are you someone who is working as a WordPress developer for a long time? OR Are you someone who is an owner of a very successful IT organization who provides WordPress solutions? Then, you must be knowing about the wp-config.php file.
The wp-config.php is one of the most potent files in the whole WordPress ecosystem, as it plays a significant role in how WordPress works behind the scenes.
Any WordPress developer has to work with this file day-in & day-out and therefore, he/she should be aware of the tricks and tips that can be helpful while working with WordPress Configuration File.
Most of the beginners don’t know how to work smoothly with the wp-config.php file, and therefore, they face a lot of problems while dealing with any WordPress projects.
Taking this scenario into consideration, today we’re going to provide with 15 handy WordPress configuration tricks which will ease out all your problems.
How To Use WordPress Configuration Tricks?
Before going into the details of WordPress Configuration Tricks, you need to be aware of how to use these tricks.
The wp-config.php file is inside the root folder of every WordPress website, and it comprises of essential configuration settings.
Most of good WordPress hosting providers come with the 1-click installation process, and the user never has to worry about setting up wp-config.php file. Due to this kind of situation, most of the developers are not familiar with the detail insights about this critical file.
However, you should be very careful while making any edits to the wp-config.php file. The reason behind that is, a tiny mistake in the code can make your website inaccessible and having WordPress Website Accessible is crucial.
So, whenever you’re making any changes to this file, please remember to take a backup.
Now, coming to the point of configuration tricks, you need to go to wp-config.php file and then, make the necessary edits. So, be very attentive while following any of these tricks.
WordPress Configuration Tricks
- Basic Settings
- Adding Security Keys
- Changing WordPress Table Prefix
- Turning On Debugging In WordPress
- Changing Your Site & WordPress Address
- Overriding File Permissions
- Changing Post Revision Settings
- Changing WordPress Trash Settings
- Adding FTP/SSH Constants
- Allow Automatic Database Repair
- Increase The PHP Memory Limit
- Moving wp-content Directory
- Use Custom User Tables
- Enable Multi-Site Network
- Securing The Configuration File
1. Basic Settings
If you’re working as a WordPress developer, then you must be knowing that there are some Things To Do Before Launching A WordPress Website. One of those things is to know the basic configuration settings.
When you’re installing the WordPress on your system for the first time, then they will inevitably be asked to fill the database settings as shown in the screenshot below.
Here, if you don’t have the wp-config.php file present, then you will be asked to create one by filling the database details. Generally, WordPress will automatically save these settings by generating a wp-config.php file.
However, if this doesn’t work out, then you need to add this file manually. For that purpose, establish a connection with your website using FTP client or cPanel. Once you’re connected, you need to rename the wp-config sample.php file to wp-config.php file.
Once you complete this task, then you can edit the newly created wp-config.php file. You need to add the database information to this file by adding the following code.
define('DB_NAME', 'database-name'); define('DB_USER', 'database-username'); define('DB_PASSWORD', 'database-password'); define('DB_HOST', 'localhost');
In the end, don’t forget to save the changes & uploading the file back to the server.
2. Adding Security Keys
If you’re working as a developer in a WordPress Development Company for a long time, then you must be knowing that the default WordPress installation comes with security keys added to your configuration file.
These keys will add an extra layer to the WordPress login as well as cookies which are used by the website.
However, sometimes there is a situation where you need regenerate the security keys. For that purpose, you should move to wp-config.php file and add the following code which will log out all the logged in users and help you to secure your system.
define( 'AUTH_KEY', 'put your unique phrase here' ); define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); define( 'NONCE_KEY', 'put your unique phrase here' ); define( 'AUTH_SALT', 'put your unique phrase here' ); define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); define( 'NONCE_SALT', 'put your unique phrase here' );
3. Changing WordPress Table Prefix
When you install WordPress on your system, the default WordPress Table Prefix will be wp_. However, many industry experts believe that you should change your WordPress database prefix to make your site secure.
For that purpose, you need to add the following line of code in the wp-config.php file
$table_prefix = 'wp_';
Now, if you’re doing this for an existing WordPress website, then remember to change the table prefix in your WordPress database.
4. Turning On Debugging In WordPress
WordPress comes with a debugging feature which allows the user to see or hide the WordPress errors while you’re in the debug mode. Now, to turn on this mode, add the following rule in your WordPress configuration file.
define( 'WP_DEBUG', true );
In addition to all these, WordPress also allows you to hide the errors on the website and save them in a log instead. For that to happen, you need to add the following lines of code to your WordPress configuration file.
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
The above code will create a debug.log file inside the wp-content folder and store all the debugging errors & notices inside this file.
5. Changing Your Site & WordPress Address
In a general scenario, you can set the WordPress as well as site URLs by moving to Settings > General page from your WordPress Admin Dashboard. However, you may not be able to perform this thing, when you don’t have access to the site, or you’ve just moved your website.
In this type of situation, if you want to change the site & WordPress URLs, then you need to add the following lines of code in the wp-config.php file.
define('WP_HOME', 'http://www.example.com'); define('WP_SITEURL', 'http://www.example.com');
Here, you shouldn’t forget to replace the example.com with your domain name.
6. Overriding File Permissions
WordPress allows you to override the file permissions only if your host has the restrictive permissions for all the user files. Most users don’t need this kind of facility, but it exists for those who need it. To override file permissions, add the following lines of code to a wp-config.php file.
define('FS_CHMOD_FILE', 0644); define('FS_CHMOD_DIR', 0755);
7. Changing Post Revision Settings
WordPress comes with a compelling feature for post revisions which allows you to undo changes to your posts & pages by reverting to the previous version as per your need.
You can disable or change post revisions settings with the use of a configuration file.
To change how often WordPress stores an autosave as a revision, add the following line in the wp-config.php file.
define('AUTOSAVE_INTERVAL', 120); // in seconds
Some articles on your website may have any number of revisions depending on how much time you took to write them. If you think that too many changes are annoying you, you can limit the number of post revisions by adding the following line wp-config.php file.
Now, for some reason, if you want to disable the post revisions feature altogether, then you should have the following line wp-config.php file.
define( 'WP_POST_REVISIONS', false );
If you still have any query in the WordPress post revisions, you should Hire WordPress Developer for that. He/She will be able to guide on this prospect.
8. Changing WordPress Trash Settings
WordPress comes with a feature called Trash which has the same functionality as that of recycle bin. When a user sends any of their posts to trash, then that post will stay in the garbage for the next 30 days, and after that, WordPress automatically deletes them forever.
You can change this type of behavior by changing the number of days for which you want the post to remain in the trash.
define( 'EMPTY_TRASH_DAYS', 15 ); // 15 days
If you don’t like this feature, then you can disable it by adding the following line of code in the wp-config.php file.
define('EMPTY_TRASH_DAYS', 0 );
One thing that you should be taking note of is that, when you define the number of days as 0, then it means that, you’ve deleted all the posts. So, an accidental click can cost you a lot.
9. Adding FTP/SSH Constants
By default, WordPress CMS allows you to upgrade the WordPress core, themes, and plugins from the WordPress Admin Dashboard. However, some hosting providers require an SSH or FTP connection each you upgrade anything in your WordPress website.
To get rid of this, you can add the following lines of code to the wp-config.php file.
// forces the filesystem method: "direct", "ssh", "ftpext", or "ftpsockets" define('FS_METHOD', 'ftpext'); // absolute path to root installation directory define('FTP_BASE', '/path/to/wordpress/'); // absolute path to "wp-content" directory define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/'); // absolute path to "wp-plugins" directory define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/'); // absolute path to your SSH public key define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub'); // absolute path to your SSH private key define('FTP_PRIVKEY', '/home/username/.ssh/id_rsa'); // either your FTP or SSH username define('FTP_USER', 'username'); // password for FTP_USER username define('FTP_PASS', 'password'); // hostname:port combo for your SSH/FTP server define('FTP_HOST', 'ftp.example.org:21');
While utilizing this code for your website, don’t forget to replace the WordPress path & ftp.example.com with your FTP hosting details.
10. Allow Automatic Database Repair
WordPress comes with an inbuilt feature for database repair & optimization. However, this feature turned off by default. To turn on this feature, you need to add the following line to your WordPress Configuration File.
After adding this line, you need to visit the following URL for database repair and optimization.
Here, don’t forget to replace the example.com with your domain name. Once you navigate to this page, you will see the options of repair and optimization as shown in the screenshot.
11. Increase The PHP Memory Limit
Some of the Most Common WordPress Errors are due to limitations of the PHP memory. For that purpose, you need to increase the PHP memory limit by adding the following line of code to the wp-config.php file.
12. Moving wp-content Directory
WordPress allows you to move your wp-content directory as per your requirement. Many experts around the globe believe that this move can strengthen your security.
To move the wp-content directory, add the following lines of code to the wp-config.php file.
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' ); define( 'WP_CONTENT_URL', 'http://example/blog/wp-content'); define('WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' ); define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');
Here, you need to replace example.com with your domain name.
13. Use Custom User Tables
By default, WordPress saves all the user data in the tables wp_users & wp_usermeta. To use the custom user tables, you need to use below function where you can specify the table in which the user information will be stored for future purposes.
define('CUSTOM_USER_TABLE', $table_prefix.'my_users'); define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');
14. Enable Multi-Site Network
Each WordPress website comes with a multi-site feature which allows you to create multiple websites using the same WordPress installation. To enable the WordPress Multi-Site Network functionality, you need to add the following line to your configuration file.
15. Securing The Configuration File
Any Custom WordPress Development company would tell you that, wp-config.php is one of the most important files in the whole WordPress installation.
Therefore, it needs to be handled with a lot of care, and you should also take the necessary step to secure this wonderful file.
By default, this file is in the root folder which meansanyone can’t access it. However, you can also move this file outside the public_html directory to restrict the access. For this thing to happen, you need to add the following code to the .htaccess file.
# Protect wp-config.php <Files wp-config.php> order allow,deny deny from all </Files>
Knowing the configuration file in detail is one of your keys to success as far as the WordPress development is concerned.
Taking this into account, here we have tried to provide with a list of 15 tricks which will help you in the long run.
If you’ve any questions or suggestions regarding this blog, then feel to ask them in our comment section. We’ll try to respond to each of your queries. Thank You.!
Looking for an IT organization that can provide world-class WordPress Development Services at an affordable rate? Then, Connect With eSparkBiz Technologies. We have a team of WordPress expert which will assist you from start to end.
Disclaimer: We at eSparkBiz Technologies have created this blog with all the consideration and utmost care. We always strive for excellence in each of our blog posts and for that purpose, we ensure that all the information written in the blog is complete, correct, comprehensible, accurate and up-to-date. However, we can’t always guarantee that the information written in the blog correct, accurate or up-to-date. Therefore, we always advise our valuable readers not to take any kind of decisions based on the information as well as the views shared by our authors. The readers should always conduct an in-depth research before making the final decision. In addition to these, all the logos, 3rd part trademarks and screenshots of websites & mobile apps are the property of the individual owners. We’re not associated with any of them.