This is the second part of my optimization series for WordPress sites which focuses on what administrators can do in order to speed up load times for the sites they manage. Part 2 focuses exclusively on some of the coding changes I’ve made to a few sites I manage in order to speed up WordPress. Part 1 of the series can be found here.
One of the great things with nearly any web content management system is its use of themes and templates. In order to make themes and templates simple and easy to use without having to change much of the code, PHP functions are used excessively so that the admin doesn’t have to do much coding (in most cases, no coding at all) in order for the template to work with the system it was designed for. With WordPress for example, simple things such as the site’s title and css file locations are dynamically called using PHP. If you plan on keeping your theme for awhile, or have designed a theme exclusive to your site, much of the dynamic PHP calls that can slow down load times can be eliminated entirely, especially with information from a theme’s header.php file.
For all of the code snippets, Planet Label has allowed me to used code snippets from their blog to use for my examples. Below are snippets of the original code and the changes I made so that less dynamic calls are made to the server.
Site Title
Original Code:
That seems like a massive amount of code for just the title of a page. Not that I also added additional formatting to make the code appear clearer and easier to read. While code like this may be necessary for dynamically rendering a site name on the fly for any site that installs it, does your site really need it now that it’s installed and that the theme will likely be used for an extended period of time or rotated seasonally? Let’s give the title a little more of a static flair instead.
Static Code
Short, simple, to the point, and one less dynamic request made to the server.
Pingback URL
Original Code
As you can see, the link for the pingback URL is also called dynamically in themes. Not sure what a pingback is? Check out the the WordPress Codex.
Static Code
RSS and Atom Feeds
Original Code
So much work for the server when it can be handled like this…
Static Code
Language Attributes
Original Code
Static Code
Content-Type Attributes
Original Code
Static Code
JavaScript
Original Code
Static Code
Stylesheets
Original Code
Static Code
You’ll notice in some of the examples that making the code static causes more code than the original code snippets. Length of code is essentially something we’re not looking into for the results, but rather the fact that less calls to the server are being made. The less the server has to work, the faster your WordPress site can deliver content to your audience. Furthermore, these changes should be made if you intend on keeping your theme for a long time or rotating it with other themes throughout the year. Finally, if you are designing a theme to release for download, it is imperative that you keep the PHP server requests in the header.php file otherwise chances are good that the theme won’t work for the other person trying to use it. Let them do the tweaking and optimizing.
Are there any other code tweaks that you recommend for speeding up a WordPress site? Feel free to drop a comment with your thoughts, opinions and suggestions. The more the better! Happy coding.
WordPress, like many other web content management systems, rely heavily on the use of plugins, libraries, and dynamic server requests using PHP to serve content to its viewers, but with all of the calls to the server, and a massive amount of plugins running on the site, overhead for a simple page load can often times become tremendous. This post is the first part of a two (or maybe more) part series on procedures a person can take to decrease load times for their WordPress install. This post will focus specifically on the plugins I use to keep load times at a minimum for my site.
Plugins serve a wide range of purposes for any developer or designer, whether it is dispatching a tweet whenever content is published, or shifting/restructuring content on a page. While plugins are wonderful and can solve many problems and provide additional functionality, it’s ideal to stick with only plugins that are needed. For example, if you are testing multiple media player plugins for audio files, keep the one media player plugin that you intend on using and delete the rest. If there is a plugin that you intend on using, but haven’t applied it to your site yet, keep the plugin disabled until you use it, otherwise extraneous requests may be made to the server where unnecessary.
On the other side of the spectrum, there are some really neat plugins that can really assist in speeding up load times for WordPress. Some plugins re-arrange code or optimize the database. Here are some of the plugins I use for my site:
Are there any plugins that you use that deserve to be on this list or an upcoming list for speeding up WordPress? Any alternatives that you recommend for the above mentioned plugins? Your input and insights are important to me, so please feel free to leave some comments expressing your experiences with optimizing WordPress using plugins.
Tomorrow’s post will focus on optimizing the header.php file that’s typically included in WordPress themes to increase performance.