10+ wp-config tricks to boost your WordPress site

by Jean. 13 Comments -

If you already installed WordPress, you know the wp-config.php file: this is the file where you set up your database connection info and define your site language. But you can do a lot more things with the wp-config.php file. In this article, I’ll show you 10+ tricks, using wp-config.php, to boost your WordPress website.

Prevent WordPress from asking FTP credentials

Paste the following line in your wp-config.php file. This file is located in the root of your WordPress install.

define('FS_METHOD', 'direct');

Please note that the code snippet provided above might not work on all hosting providers, and might even cause security issues if your host is badly configured, so avoid using it if you’re not sure about your hosting.

I use VidaHost on CatsWhoCode, WPRecipes and my other blogs. WP Web Host is also good for smaller websites.

Source: http://wp.tutsplus.com/tutorials/security/conquering-the-wp-config-php…

Tell WordPress to remember your FTP credentials

If the above method do not work on your server, or if you don’t want to implement it for some reason, here is another useful snippet. This one simple tells WordPress to remember your FTP credentials so you won’t be asked again when an upgrade is available.

define('FTP_HOST', 'ftp.yoursite.com');
define('FTP_USER', 'Your_FTP_Username');
define('FTP_PASS', 'Your_FTP_password');
define('FTP_SSL', true); // If you can use a SSL connection set this to true

Source: http://admindaily.com/how-to-stop-wordpress-ftp-to-upgrade-plugins.html

Disallow direct file edition

By default, WordPress allows the site administrator to directly edit themes and plugins files through a built-in editor. This is very useful, but if you’re building a site for a client you probably don’t want him to break the site. Here’s a simple way to disallow direct file edition.

define('DISALLOW_FILE_EDIT', TRUE);

Source: http://www.wprecipes.com/how-to-hide-theme-editor…

Automatically empty trash

If you want to define how often the trash should be automatically emptied, here’s the right way to do it:

define('EMPTY_TRASH_DAYS', 1);

Replace 1 by X to empty spam comments automatically every X days. That’s simple as that!

Source: http://www.wprecipes.com/how-to-automatically-empty-trash-on-a-daily-basis

Easily move your WordPress install

WordPress supports an automatic relocation method intended to be a quick assist to getting a site working when relocating a site from one server to another.

To move your WordPress website easily, paste the following line into your wp-config.php file and then follow the steps explained on WordPress Codex.

define('RELOCATE',true); 

Source: http://wp.tutsplus.com/tutorials/security/conquering-the-wp-config-php-file…

Increase WordPress memory limit

By default, WordPress is configured to limit the php memory it uses to 32M. If you receive a message such as “Allowed memory size of xxxxxx bytes exhausted”, you might want to increase this limit, as shown below:

define('WP_MEMORY_LIMIT', '96M');

Source: http://digwp.com/2010/08/pimp-your-wp-config-php…

Automatic database repair

Added with Version 2.9, there is automatic database optimization support, which you can enable by adding the following define to your wp-config.php file only when the feature is required.

define('WP_ALLOW_REPAIR', true);

Source: http://digwp.com/2010/08/pimp-your-wp-config-php…

WordPress debugging, the easy way

When developing or debugging, it is useful to display errors. But when your site is live, you might not want to show your potential errors to the entire world. Here is simple solution to display errors only when a debug=debug parameter is found on the url.

The first thing to do is to paste the following code into wp-config.php:

if ( isset($_GET['debug']) && $_GET['debug'] == 'debug')
  define('WP_DEBUG', true);

Once done, simply add a GET parameter to the url of the page you’d like to debug, as shown below:

http://www.wprecipes.com/contact?debug=debug

Source: http://yoast.com/wordpress-debug/

Force SSL usage on your wp-admin directory

If you’re running WordPress on a server that supports SSL, you might want to force SSL usage on all admin sessions. To do so, simply define the FORCE_SSL_ADMIN constant in your wp-config.php file, as shown below:

define('FORCE_SSL_ADMIN', true);

Source: http://www.wprecipes.com/how-to-force-using-ssl-on-wp…

Block external requests

Since version 2.8, WordPress allows you to define constants to control access to specific hosts from behind a proxy server.

define('WP_HTTP_BLOCK_EXTERNAL', true);

It will block external requests from that time on. Though, some plugins need external request to work properly. If you experience problems, you can define a whitelist by pasting the code below into wp-config.php. Don’t forget to replace my url by the one needed by the plugin, and note that you should allow access to api.wordpress.org in order to ensure proper functionality of core files and plugins.

define('WP_ACCESSIBLE_HOSTS', 'wprecipes.com');

Source: http://www.wprecipes.com/block-external-requests-on-your-wordpress-blog

Define website url

Introduced in WordPress 2.2, WP_SITEURL and WP_HOME overrides the wp_options table value for home but does not change it permanently, which can be very useful when you move a website to a new domain.

define('WP_HOME', 'http://catswhocode.com'); 
define('WP_SITEURL', 'http://catswhocode.com');  

Source: http://digwp.com/2010/08/pimp-your-wp-config-php…

  • http://brandonsheley.org Brandon Sheley

    The direct file restriction is very important, thanks for the info. I’ve been wondering how to do this for a while now.

  • chrismccoy

    UPLOADS is another constant thats not very well known, as of wordpress 3.5 the UI has stopped the ability to assign the uploads directory, most people just leave it as it is, but I had a client who stores his images in domain.com/pics/ so he sets that via the settings, you will need to do it via the constant as of 3.5

  • http://www.webdesigncc.com/ Peter North

    Nice tricks and each of them is explained in way that it become easy to understand. I was using some of them to boost up my website. Now I will add other tricks as well.

  • http://www.maktubteahouse.com Jo

    I feel terribly ignorant in not really understanding most of these but feeling like I should. My host provider has a one click install, I ftp up the files and bingo.

    I am eternally grateful to you though for giving me an answer to increasing the memory from 32mb. This has been nagging me for a while and I felt I should finally sort it out.

    Very glad I found you, I suspect I have a lot of reading to do.

  • http://www.cbopt.com Chetan Bhasin

    I have never played with jQuerry plugins, and have no idea how to use them. Can you tell me how I can use them and include in my webpages (standalone and of cms like wordpress, joomla etc.).

  • http://wpthemesdaily.com Robert

    I always get stucked at increasing memory for WP blogs. This nice tip saves my life :) Rather than burrying myself downward these ugly codes, a simple line on WP Config will do it immediately. Thank you

  • http://ijustutter.com Mrinal

    I return here every now and then. At every visit I learn something new. That memory limit and Debug thing actually feels like the most important thing to optimize site. Thanks.

  • http://www.stevendobbelaere.be Steven

    Nice will try some of those immediately

  • http://endcore.com Christian Lang

    Oh yes, thanks for this post. I like “Tell WordPress to remember your FTP credentials”… spend so much time for this…

  • http://www.wpsnipps.com Kris

    Increase WordPress memory limit hack is cool but does it work with every web server if there is limitations.

  • http://www.techpages.org mohan

    I already tried some of the above tips,let me try rest of the tips.Thanks for the useful tricks.

  • http://geekingsimply.wordpress.com/ Darko

    Very good tutorial but I have a question for the last trick. Why define website url through wp-config when moving website to new domain is useful? There is option to set those in wordpress settings. I want to move one of my websites to another domain so I’ll wait for the answer.
    Thanks

  • http://www.gigroup.it/ MICHELEANNICCH3

    http://novaratorino.wordpress.com