Optimizing the WordPress Configuration File

Optimizing your WordPress configuration file (wp-config.php) can change some of WordPress’s default behaviors and improve the speed at which your website loads. Improving the way WordPress works is easy. Here are a few of the most popular configuration tweaks.


Post revisions, autosave, and trash handling


WordPress autosaves revisions of your posts and pages, and you can send posts and pages to the trash can, instead of completely deleting them. WordPress saves unlimited revisions and sometimes, depending on how often you edit and reedit posts and pages, the saved revision list can get pretty long. You can limit the number of revisions that WordPress will save by adding the following line to the wp-config.php file:


define (‘WP_POST_REVISIONS’, 3); // limit number of revisions to 3

You can also completely disable the default revision feature by adding this line to the wp-config.php file, on its own line:


define (‘WP_POST_REVISIONS’, false); // disable post revisions

WordPress creates these revisions through the Autosave feature. By default, WordPress automatically saves a post revision every minute. If you take a long time to write a post, you could rack up dozens of post revisions, which are stored in the database and take up room. You can change the autosave interval by adding this code to the wp-config.php file on its own line (this code changes the autosave interval to 160 seconds, specifically — you can choose any time interval you want):


define (‘AUTOSAVE_INTERVAL’, 160); // in seconds

The Trash feature in WordPress gives you a safeguard against permanently deleting posts by mistake. You can visit the trash can any time and permanently delete the post or page, or you can leave it there and WordPress automatically empties the trash can every 30 days. If you want to adjust this time interval, you can add the first line of code to force WordPress to empty the trash weekly, or the second line to disable the trash feature, completely, as follows (on its own line):


define(‘EMPTY_TRASH_DAYS’, 7); // empty trash weekly
define(‘EMPTY_TRASH_DAYS’, 0); // disable trash

Site and WordPress installation web address


One of the most common template tags for use in a theme is the bloginfo(); tag, which has several parameters you can use to call different bits of information about your site (like the site name and description, for example). You then can call in different theme template files and graphics (or images) into your theme. For example, the URL of your website can be defined in your template files with the following template tag:


<?php bloginfo(‘url’); ?> // Site URL

That template tag tells WordPress to communicate with the site database, locate the site URL, and return it back to the template or plugin file that’s making that database call. You can reduce the number of database calls (thereby, speeding up your site) by defining the site URL in the wp-config.php file by inserting the following two lines on their own lines (replacing yourdomain.com with your actual domain name, of course):


define (‘WP_HOME’, ‘http://yourdomain.com’); // site address
define (‘WP_SITEURL’, ‘http://yourdomain.com’); // wordpress address

Template and stylesheet path


Just as with the site URL from the preceding section, many themes and the WordPress core code look for your WordPress theme template and stylesheet directory through the following WordPress template tags:


<?php bloginfo(‘template_directory’); ?> // template directory
<?php bloginfo(‘stylesheet_directory’); ?> // stylesheet directory

Once again, you can significantly reduce the number of calls to the database for the template and stylesheet directories by directly defining them in your wp-config.php file. To do so, add these two lines of code (replace absolute/path/ with your own server path and replace /themefolder with the name of the theme folder you use currently) on their own separate lines:


define(‘TEMPLATEPATH’, ‘/absolute/path/to/wp-content/themes/themefolder’);
define(‘STYLESHEETPATH, ‘/absolute/path/to/wp-content/themes/themefolder’);

Increasing PHP memory limits


Most web hosting providers limit the amount of memory any one PHP script or program file can use on the web server at any given time. PHP is at the core of WordPress, and by default, WordPress attempts to set the PHP memory limit to 32MB.


To help resolve the PHP memory limit errors, within the wp-config.php, define the maximum amount of memory that PHP can use by writing one of these three lines of code, depending on how much memory you allow PHP to use on your site, and adding it to the wp-config.php file on its own line:


define (‘WP_MEMORY_LIMIT’, ‘64m’); // increase limit to 64M
define (‘WP_MEMORY_LIMIT’, ‘96M’); // increase limit to 96M
define (‘WP_MEMORY_LIMIT’, ‘128M’); // increase limit to 128M

Some hosting providers disable the ability to increase PHP memory limits on your web hosting account.




dummies

Source:http://www.dummies.com/how-to/content/optimizing-the-wordpress-configuration-file.html

No comments:

Post a Comment