I highly suggest changing one line at a time and testing it before going on to the next. This will help find any errors that popup through misplaced tags.
In the WordPress world, <?php denotes a database lookup of some sort. These are the lines that we want to try to remove as much as possible, but there are a few other locations we can clean up also.
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="Content-Type" content="
;
charset=" />
can be streamlined to:
All we did was remove the database lookup by hard coding the variables that would have been found. It’s critical to note that the charset maybe different for your blog depending on the language of the blog. The exact charset you should use is beyond the scope of this post, if you want to know more about charsets, here are some good links:
WordPress Database Charset and Collation Configuration
How to Avoid Character Encoding Problems in PHP
Seeing Weird Characters On Your Blog? Here’s How To Fix Your WordPress Character Encoding (Latin1 to UTF8)
For SEO reasons, we probably want to keep the next php lookup:
<meta name="generator" content="WordPress " />
But the title lookup can streamlined drastically
As the blog author we know what the page title (wp_title,) and bloginfo already are – in fact when first setting up WordPress these were likely two of the very first things entered. Just in case it’s needed, these are under General -> Settings. The page title is “Site Title,” and bloginfo is the “Tagline” field.
So we can minimize this line to:
Pacific Northwest Photoblog - Travel Photos and History from the Pacific Northwest
The next line we can remove is the favicon, this is the 16×16 pixel icon that shows in the address bar and is saved when a page is bookmarked. The actual name can change from theme to theme, but it will always be located in the theme directory under wp-content. So this line:
<link rel="shortcut icon" href="/icon.png" type="image/x-icon" />
becomes:
The icon may also have an .ico extension, or it can be something called favicon.png.
The next database lookup finds the pingback url. Note that this is an href= link that is looking for an html link, the database lookup simply grabs the webpage url, then appends /xmlrpc.php to it. All we do is add the link ourself.
<link rel="pingback" href="" />
In the original code above, the next database lookup is a critical one. This brings up the actual “body” of the blog. This could a static page, or a list of posts, depending on what settings were chosen in the blog. Either way, skip over the following database lookup because it is hugely critical.
<body >
In the header wrapper though, we have another familiar line:
<a href="/">
●
This is almost exactly the title line from above, but with an href link to the home page in it.
● Travel Photos and History from the Pacific Northwest
At this point the header.php file is streamlined quite significantly. Next we go to the footer.php file as there is a couple more database lookups we can hardcode here also.
Original footer.php file:
As you can quickly see there is another “bloginfo” lookup here including an HTML link, just like the title lookup had in header.php.
Some people would suggest removing the link to the Theme artist if it exists, along with other “useless” information. Personally I prefer to leave it to give credit to the people who provided the theme for free, but it does take a little resources to serve up. Every line removed decreases the load time slightly and will make a big difference if a blog is getting thousands of hits at once.
But we can do one other thing – remove the year lookup as defined by this piece of code:
Some blogs will have an RSS feed link in this area. For posts this typically look like
My rss feed is http://PNWPhotoBlog.com/feed/ . But RSS Feeds can look a little different, especially if you use Feedburner. So be sure to check the exact link before editing the code.
Personally I do not care if people subscribe to my comments via RSS, but I would like more readers to subscribe to my general RSS feed. My full code now looks like this:
By these directions we’ve removed sixteen full database lookups! This halved the loading time of my webpage, PNWPhotoblog.com. That is quite a difference, don’t you agree?