Looking for tips and tricks on how to speed up your WordPress blog? wp-config.php is one of the WordPress configuration file which you can leverage to optimize the performance.

One of the option to speed up your WordPress is install W3 Total Cache plugin. W3 Total Cache is better than WP Super Cache plugin as it provides more option for caching such as page and SQL query caching together with CDN platform.

Although you have W3 Total Cache plugin installed which optimize the page and SQL query caching, it is always recommend to look on how to speed up WordPress further.

One of the place you should look on to speed up WordPress is $HOME/tmp/mysql_slow_queries. Inside here has the log entries that show all the long running SQL on your WordPress database where you need to do tuning.

WordPress Slow SQL Query

SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'

wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id 
= wp_term_taxonomy.term_taxonomy_id)  WHERE 1=1  AND 
wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id 
IN ('61') AND wp_posts.post_type = 'post' AND
(wp_posts.post_status = 'publish') 
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 2, 2

SELECT * FROM wp_comments WHERE comment_post_ID = 7900 
AND comment_approved = '1' ORDER BY comment_date_gmt ASC

SELECT p.* FROM wp_posts AS p  WHERE p.post_date < '2009-03-16 03:52:21' 
AND p.post_type = 'post' AND p.post_status = 'publish' 
ORDER BY p.post_date DESC LIMIT 1

SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (3702)

This is the list of slow WordPress SQL query which cause the hosting server having high CPU throttling.

Since the query list is WordPress standard SQL, it’s hard to tune the query at the first place. What we can do is by extending the value of caching time in W3 Total Cache which will reduce SQL call to the database.

wp-config.php Hacking To Speed Up WordPress

Another option that you can try is to reduce the number of SQL query to your WordPress blog database. The theme header.php and footer.php might have list of SQL call to database to get the stylesheet and template directory as below.

<?php get_bloginfo('stylesheet_directory'); ?> 
<?php get_bloginfo('template_directory'); ?>
<?php bloginfo('stylesheet_directory'); ?>
<?php bloginfo('template_directory'); ?>
<?php get_stylesheet_directory(); ?>
<?php get_template_directory() ?>

It’s recommended to replace these value in header.php and footer.php by hardcoding the value of your domain site to reduce SQL call to the database.

If not you can choose to place the value inside the wp-config.php file where it will make your header.php and footer.php to refer this flat file instead of database.

define('WP_HOME', 'http://www.domain.tld');
define('WP_SITEURL', 'http://www.domain.tld');
define('TEMPLATEPATH', '/full-path-to-wordpress-root/wp-content/themes/xyz');
define('STYLESHEETPATH', '/full-path-to-wordpress-root/wp-content/themes/xyz');

Another method you can use to speed up your WordPress is by putting in the secret key in wp-config.php file.

You may obtain the secret key by navigating to http://api.wordpress.org/secret-key/1.1/ and copy it to wp-config.php. WordPress will refer to the value in wp-config.php and thus it will reduce the SQL call to the database.

define('AUTH_KEY', 'E6tlb]UJf`|k|i4U(_|>B{BW0iip%4LjQwv`2-Y#zQlPU-waj 4&H/E?z#[-LBXr');
define('SECURE_AUTH_KEY', 'pu|U2jP|gpA?O+PRc|Y&x&dU@WZ{)`[4sA1yf<=7=+%3]lsbE|#B6-{+');
define('LOGGED_IN_KEY', '!,i#HoH*2dTz|1UQwXux]iQ$1*!|DZ ,6GQfh%Fw-GUx*LHG=e2szWP8Ar8W');
define('NONCE_KEY', 'gAMd*`cy)`:WWZFkjjo*nDLw2Gx8hS2}@I-ask2>V ||bW1LPu9bZD<o5k!DJzj2');

After adding the secret key manually to the wp-config.php, we notice better WordPress speed performance and it reduce the number of WordPress slow SQL query.

The 2 line configuration is optional as the first line will increase WordPress memory limit to 64M. While the second line will change the auto save interval to 300 second (default is 60 second).

define('WP_MEMORY_LIMIT', '64M');
define( 'AUTOSAVE_INTERVAL', 300 );