Generally speaking WordPress is fast. And this is the case even with large websites with tens of thousands of posts. Mostly, speed depends on the theme and than on the plugins. But in many cases the slowest part is the WordPress core. Here is how to speed it up.
SQL execution background
Most of the SQL queries WordPress uses are fast. They will get slower with more complex filters added to the query, but such queries are rare. In most cases you can’t do much to speed them up. Some of the operations WordPress runs will execute more than one query: filtering posts by category or tag, metadata queries. This is done because 2 simpler queries are usually faster than one query using joins.
When number of posts rises, queries will tend to slow down. If the query relies on columns that are indexed (post ID for instance), speed will remain the same and number of posts will not affect speed. But, in some cases queries will rely on columns that are not indexed or even if they are indexed, index is not having effect. Such columns are ususally date/time columns.
Speed problems
While main SQL queries will usually remain fast, even with default configuration of WordPress, default theme and usual plugins, there are SQL queries in the WordPress core that are very slow. And most of the are not needed at all. This time we will focus on SQL queries that are part of the page header. Using filters WordPress core adds several functions to the header that are used to generate additional tags. These tags are adding additional URL’s inside the website: previous post, next post, parent post (for hierarchical post types), first post in category. These filters can generate 5 to 10 SQL queries, and in some cases they can take longer to execute than all the other SQL queries on the page combined!
These header tags look something like this:
<link rel='index' title='Dev4Press Premium Plugins and Themes' href='http://www.dev4press.com/' /> <link rel='start' title='Plugins' href='http://www.dev4press.com/category/plugins/' /> <link rel='prev' title='GD Press Tools' href='http://www.dev4press.com/plugins/gd-press-tools' /> <link rel='next' title='GD Star Rating' href='http://www.dev4press.com/plugins/gd-star-rating' />
Browsers can use (but mostly don’t) these to prefetch pages while you browse the website based on these links. I am not aware of any other important use for them. I always disable these, because I don’t see any real and useful reason to have them in the first place.
Adjacent Posts filter uses date column in the post (twice), and that is not as fast as other types of indexed columns are. When a website is small it’s not a problem. But on a website with few thousands or more than 10.000 posts this will cause trouble. I am working on a website with 250.000 posts. This action and 2 queries it generates can take more than 2 seconds to run on a very fast dedicated VPS server. Add to it other header link queries, and they can take more than 3 seconds to run. And that is just too much. Things get just much worse in case of hierarchical post types.
Solution
Simple. Remove the filters. If you don’t have any use for this header links you can remove the filters. I measured some of the pages. In some cases page took 3.54 seconds to execute all SQL queries. Then, I disabled these filters, and SQL queries are executed in 0.02 seconds. Also, page needs now 7 SQL queries less. If you want to manually add code to remove the filters, add this to your theme functions.php or your plugin. It’s better to run this on init action, I had some conflicts if executed before.
<?php
add_action('init', 'remove_header_links_actions');
function remove_header_links_actions() {
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
}
?>If you don’t like messing with the code, you can use my GD Press Tools plugin (only Pro edition has the options to remove these: plugin Settings -> Content -> Header). Also, my xScape based premium themes have options to disable these actions, it’s built into the framework so all my themes have it.
Conclusion
I will search further for more things you can do to optimize websites, so more posts like this will be added. If you have some more suggestions on WordPress speed improving, please leave a comment.






Comment Link
functions.php
Comment Link
Thanks, fixed.
Comment Link
Thanks a lot.
Waiting for other parts