More theme optimization

Another theme optimization, which can speed up sites that are operating under heavy load is to hardcode as much of the theme's content as possible.

Take a look at the header.php file. (I'm using the default header for this example, as it's fairly simple, so the code is clearer.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/19 99/xhtml" <?php language_ attributes(); ?>>

<head profile="http://gmpg.org/xfn/11">

<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"

type="text/css" media="screen" />

<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>"

<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>"

<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<style type="text/css" media="screen"> <?php

// Checks to see whether it needs a sidebar or not if ( !empty($withcomments) && !is_single() ) { ?>

#page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-<?php bloginfo('text_direction'); ?>.jpg") repeat-y top; border: none; } <?php } else { // No sidebar ?>

#page { background: url("<?php bloginfo('stylesheet_directory');

?>/images/kubrickbgwide.jpg") repeat-y top; border: none; } <?php } ?>

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

<div id="page"> <div id="header">

<div id="headerimg">

<h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1>

<div class="description"><?php bloginfo('description'); ?></

div>

In the above file, all instances of PHP code that are being used to determine something that is fairly unlikely to change (for example, the name of the blog or the path to a theme) have been highlighted.

You could remove the PHP code in each instance and hardcode the value in place. So, for SlayerCafe, you would replace <?php bloginfo('name'); ?> with The Slayer Cafe, and

<?php echo get_option('home'); ?> with http://www.slayercafe.com. Before you try this, take a backup of the file!

There are many other examples of this. If you look for the part of your theme file where the list of pages (for example, "About Us") is displayed, you will see that WordPress MU uses a function to display those pages. If you're confident that you won't be adding new pages very often, you could remove that function call and instead hardcode links to the pages that you want to have listed.

I'd recommend taking the time to do these edits on your main blog's theme files, as well as the theme files for BuddyPress and bbPress. Only hardcode values that are not likely to change often such as links to the home page, the title of the blog, and so on. If you decide to edit the themes that will be available to your users, only change things such as the HTML type and the paths to the theme files. Remember that there is one theme shared among many users, so you can't hardcode in every user's blog title!

Compressing the images used in your site's themes will save you some bandwidth. Check to make sure that all your images are saved at the size they are used. All too often, designers save a large image in a high resolution (for example, a logo) and use that large image file on their site, setting the image's dimensions so that it appears much smaller. Instead of wasting your bandwidth, and that of your visitor by making them download a file that could be hundreds of kilobytes (or more!) in size, why not make a smaller, lower resolution version of that file for the Web?

Was this article helpful?

0 0

Post a comment