Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 6 • Advanced Theme Usage 169


With that in mind, what can you do to speed up your theme? Try these tips:


◾ Clean out unnecessary code. Most themes can use another going-over or two after they
appear to be finished.
◾ Minimize PHP usage. Don’t use dynamic functions and whatnot with PHP if you expect
large amounts of traffic; hardcode as much as you can into the theme instead. This will
obviously make the theme more tied to your particular site, but sometimes that is what’s
needed.
◾ Beware of plugin overload. Plugins are great, but sometimes they aren’t all that well
coded. At the very least, they represent one or more PHP queries and possibly database
processing. You should consider each of them carefully. You can save yourself a lot of
headache if you stick to reputable plugins, preferably from the WordPress.org plugin
repository.
◾ Think about outside services. This is not strictly in your theme, but outside services such
as chat widgets or Twitter badges take time to load and will affect the performance of the
site in the eyes of your visitors.
◾ Optimize the server. Your hosting solution of choice may offer PHP accelerators and
caching for often-called functionality. They might or might not be running programs
such as Varnish, and perhaps there are things in the web server software that could be
tweaked or removed to speed up things; it all depends on the setup. Talk to your hosting
provider for options and then make sure that they are compatible with WordPress; all
may not be.
◾ Consider WordPress caching. There are caching plugins for WordPress that store static
files rather than serve data from the database all the time. This can actually speed up a
site, so it may be worth employing.
◾ Tighten the files. You can Google your way to both HTML and CSS compressors, which
tighten your files but make them a whole lot harder to read. Be sure to check the output
to ensure that the compressors’ scripts haven’t added something malicious. You can never
be too sure.

In the end, tightening a WordPress theme is more or less the same as tightening any site.
Good and tight code, preferably valid, will load faster than clunky and bloated code, so get it
right from the start.


If you’re doing everything right but your WordPress site keeps chugging slowly, then maybe
you’ve outgrown your host. After all, when all the PHP calls are minimized, the server is
running everything it should and nothing more, the code is tight and valid, and you’ve got
your accelerators and caching plugins working, then there’s just not much more that you can
do other than crank up the voltage to power your beast. Although you shouldn’t look for a
new host just because your site is performing poorly, it might be the solution to the problem,
especially if your site has grown rapidly.

Free download pdf