In the above image you can see your WordPress before reading this post, and after the optimizations you will make after you read it. :)
This article contains a lot of suggests to optimize your WordPress installation and make your site faster and better.
Add cache to make WordPress faster
The really important help for page speed is caching. Caching means that WordPress creates a static HTML version of your pages (for posts, pages, tags, archives… for every page) and serve the static version to not logged in users. Only logged in users will see the real WordPress pages. This change lets you go faster because it cuts off database usage and every other WordPress job.
Sometimes caching brings some minor problems such as difficulties in refreshing cache and see the last versions of contents, but it’s really the most important thing to do if you need speed, especially if you have a lot of users visiting your site.
Since caching works only for not logged in users, your WordPress will work better if you have a small number of logged in users (authors, or buyers for example), whereas if you have a lot of logged in users (for example if you have build a community with WordPress) caching doesn’t work too much.
The most relevant, and most used, caching plugins are WP Super Cache and W3 Total Cache, they both are free and you can find them from the WordPress “add new plugin” button.
Use a CDN for a faster WordPress
If you have already tried plugins for cache and you need more speed, consider to find (buy) an external Content Delivery Network (CDN). That is to say a service that lets you easily store copies of your media files on an external array of servers located in many different countries around the world.
Such a big service brings two improvements: first the server where you have your WordPress installation receives less calls for files and this reduces the amount of work to do; second, CDNs are made with servers spread around the world to serve contents from the nearest server to the user, and if content is near it’s downloaded faster.
Remove plugins is gold activity to optimize WordPress
WordPress Plugins are really wonderful, you can try everything with them, and they let any user achieve good results without writing one line of PHP code. But they introduce some problems: the code of every active plugin is read everytime you run a page, a post, an archive, an admin page… any page. Everytime a user interact with your WordPress all active plugins are read and executed.
Moreover, which plugins have you installed? Can you trust them? I don’t mean for security reason (even if a security/privacy issue really exists), but for performance reasons. If a plugin make some action in a wrong way (or has a bug) it slows down your site.
So remove unused plugins, investigate better what they do, sometimes you need only a few lines of code of that plugin. Copy and customize those lines in your functions.php
file.
If you are here to optimize Wordpress, and you’re thinking that some slowing down depends on a plugin, you can try to deactivate plugins one by one and see if there is an improvement in performances. If you prefer, there is a tool to analyze plugins that can make some performances test on your plugins without deactivating them, it’s the P3 Plugin Performance Profiler.
Optimize database to optimize WordPress
I know that WordPress database is ok, it’s made by very good developers and you don’t have to optimize the tables structure or add indexes. But you have to fix something periodically. For example, it’s a good thing to remove revisions of old posts, remove old auto draft, remove spam or trashed comments. All these records make your database bigger and bigger always means slower. When you delete records from a table you have to run also some MySQL commands like OPTIMIZE
and REPAIR
, to reorganize the files of the database to work properly. You can make your own PHP script to do it or you can simply install a plugin, to do this I suggest Wp Optimize.
Most MySQL servers use MYISAM
engine, which is faster for reading but is slower for writing, since a write command on a table (such as an insert of a new post, or a new comment) locks the table to write and while it’s locked nobody can read it. Sometimes I found useful switch some table to INNODB
engine.
Check your header.php and footer.php
Take some time to analyze the content of the head tag of your pages.
What is bad: many links to CSS files or JS files could be a problem since any call is new traffic for your server and new work for the browser. If you can move your JavaScript at the bottom of the page, in the footer. You can also join JS files and CSS files but render to preserve the order. If you have many plugins they probably insert javascript scripts inclusion in your header and you can’t easily change them. This is another sign that indicates that you’ve added too many plugins to your site.
In your <head>
tag there are also some tags that aren’t really needed and removing them is useful also to hide informations about your platform, which sometimes lead to more security:
add_filter('xmlrpc_enabled', '__return_false'); function removeJunk() { remove_action( 'wp_head', 'rsd_link' ); remove_action( 'wp_head', 'wlwmanifest_link' ); remove_action( 'wp_head', 'wp_generator'); remove_action( 'wp_head', 'feed_links_extra', 3); } add_action('init', 'removeJunk');
Let’s see those lines one by one:
xmlrpc_enabled
: The first line suspends XML-RPC
which is a protocol to let other clients interact with your WordPress. It’s used, for example, in mobile apps that can be used by your authors to edit posts from smartphones. But it’s also used to insert spam in your comments or create fake subscribers users. If you don’t edit your site with external applications. you don’t need it and you can disable it.
rsd_link
: The RSD link is another pointless line you may have in your <head>
tag. RSD stands for Really Simple Discovery and it’s another way that WordPress can interact with external tools used for blogging. Having the link in the header is not a security threat, but if you are not using any Really Simple Discovery services then you can remove.
wlwmanifest_link
: WLW stands for Windows Live Writer that is another tool to simplify blogging and this line of code in your <head>
tag helps this software to interact with your WordPress. If you don’t use it you don’t need it.
feed_links_extra
: in WordPress you can get an RSS feed for every post, in every single page/post feed you will find the comments for that page. If comments are not the centre of your blog you can safely remove these feeds.
If you want to remove also the main WordPress comments feed and keep only the post feed, you have to remove the feed_links
action and add it back without comments feed:
remove_action( 'wp_head', 'feed_links', 2 ); function add_only_main_feed() { echo '<link rel="alternate" type="application/rss+xml" ' . 'title="'.get_bloginfo('name').'" href="'.get_bloginfo('rss2_url').'" />'; } add_action('wp_head', 'add_only_main_feed');
Control the JPG quality and the size of your images
By default WordPress set JPEG quality to 90%. Every image thumbnail WordPress creates when you upload an image is made with that quality. You can reduce to 85% or 80% and this will help you to reduce the image size of any picture without losing quality, since 80%-85% it’s really good enaugh:
add_filter( 'jpeg_quality', create_function( '', 'return 80;' ) );
Config properly the thumbnails size in Settings>Media, because the images you use in your theme could be very big or could be wrong. If you’re making a restyling of an existing site check the size, width and height, of the images you use. Use the thumbnail size when you display small images. Don’t use big images for small size, because you’re losing page speed. During a restyle you can silently change the size of thumbs and use a plugin OTF Regenerate Thumbnails that resize the old images to the new sizes in background and after a period you can deactivate the plugin.
Critical WordPress plugins
I’ve noticed that there are some very useful plugin which are crucial: here is a list of features needed in a WordPress site but also critical if not well done.
XML sitemaps: a sitemap is a list of the urls of a site in a specific XML format, which you have to send to Google (throught the Google Search Console once known as Webmaster Tools). Sitemaps are used by search engines to receive a list of urls without spidering all your site. Plugins that make sitemaps are critical because they can slow down the site when they create the sitemap, especially if you have thousands of posts. If you need a sitemap (and yes, you need it) you have to find a file that doesn’t do this thing at every save, or at every delete, or every time a new tag is created… but they have to do the job without slowing down the server in the most silent way. I’ve tried many and suggest these: Better WordPress Google XML Sitemaps (which supports also Googel News sitemaps) and Yoast SEO because it does a lot of things and also Sitemaps.
Multilanguage: if you need the multilanguage feature on your blog I suggest the easiest solution with a plugin. I don’t want too many plugin on my site, but if I need multilanguage the plugin way is the fastest solution. I’ve tested and choosed WPML, which is a good pluign but you have to pay it. This plugin needs to interact deeply with WordPress, because it lets you translate everything, but sometimes slows down the site.
Social buttons: another critical plugin family is social plugins, since they can add a lot of stuff but in most cases you need only the sharing buttons for Facebook, Twitter and a few of them. You don’t need external plugins for social buttons because you can handle it with a small piece of code. Here is an article about social buttons.