Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

WordPress Optimization/WordPress Performance

This article is part of a series on WordPress Optimization.

Plugins

The first and easiest way to improve WordPress performance is plugins. Deactivate and delete any unnecessary plugins. Try selectively disabling plugins to measure server performance. Is one of your plugins significantly affecting your site's performance?

Then you can look at optimizing plugins. Are plugins coded inefficiently? Do they repeat unnecessary database queries? WordPress has its own caching system, so generally speaking, using functions like get_option(), update_option() and so on will be faster than writing SQL.

Themes

After plugins come theme optimization.

  • Image Files
    • Are there any unnecessary images? (e.g. Can you replace some of the images with text?)
    • Make sure all image files are optimized. Choose the correct format (JPG/PNG/GIF) for the type of image.
    • Smush.it and WP Smush.it plugin can also help.
  • Total File Number/Size
    • Can you reduce the number of files needed to display the average page on your site?
    • Combine multiple CSS files into a single, optimized file.
    • Minify CSS and JavaScript files.
    • If necessary, look into plugins to help this process (e.g. Head Cleaner and WP Minify).
  • Query Reduction/Optimization
    • Can static values be hardcoded into your themes? This will mean you have to edit code every time you make changes, but for generally static areas, this can be a good trade off.
      • For example, your site charset, site title, and so on.
      • Can you hardcode menus that rarely change? Avoiding functions like wp_list_pages() for example.

We have seen themes which put 3x extra load to the server. Turned out it caused 3x more database queries - which is bad in itself. Then we found out that some of the queries are unoptimized. Not good.

You can also use offloading to optimize your theme.

PHP OPcache

Because WordPress is PHP-based, it contains a large amount of code that must be "parsed" by PHP on every single page load; if you are using a heavy theme or plugin, or a large number of plugins, the amount of PHP code grows exponentially.

In many server environments (especially shared hosting), this "parse" time can greatly affect performance, adding several seconds to the total time it takes to finish loading a page. This is where OPcode caching can help, sometimes drastically, as it avoids the need to (re)parse PHP code too often, by way of "caching" the PHP content in a temporary cache.

Throughout its lifetime, PHP has supported various OPcode caching extensions. For many years, the most popular one was called Zend, which was a proprietary third party script, followed by APC, which was also maintained by a third party. However, upon the release of PHP 5.5, Zend decided to open-source their code and contribute it entirely to the PHP project, at which point it was included (and enabled by default) as part of PHP installations.

OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request. -- PHP.net

This is one of the reasons why it is so important to upgrade your PHP version. Many web hosts allow you to upgrade by request, while others do it automatically. And while OPcache is supported by PHP 5.5+ it has several more options available in PHP 7+ (along with generally faster PHP performance), so it's a good idea to stay as updated as possible.

Further Reading:

Further Reading

This page is marked as incomplete. You can help Codex by expanding it.