With the release of WordPress 2.7 just around the corner, it’s time to check on your theme and add in the new functionality available to make the most of it. Also, if you currently offer themes either as free or premium, then these changes are definitely something you need to be adding in.

There are 3 main changes for your theme files to consider – Post Classes, Logout Links and Comment Display.

Post Classes

The first new feature is a new template tag post_class(). This should be used within the loop to replace the class given on each post container, usually a div. You’ve possibly got an opening div within the loop (so it wraps around each post on say the front page) which looks something like

<div id="post-<?php the_ID(); ?>" class="post">

With the new post class feature, we replace the class with the new template tag ie.

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

This addition will then add a number of classes to the div such as post, category-slug, tag-slug (where ‘slug’ is the slug for the category/tag). It will also add the class ‘sticky’ for those that have been made a sticky post in the admin (a new feature of WordPress 2.7).

You can also pass parameters to this function, which will then be added to the class list. So for example, if you wanted to use a class called ‘entry’ (another popular class name with existing themes), you could add this in as a parameter. You can add in multiple additional class names, just separate them with a space eg.

<div id="post-<?php the_ID(); ?>" <?php post_class('entry class2'); ?>>

Logout Link

Most themes have a log out link at least in the comments.php template. Up until now the code for this has been similar to

To logout, <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">click here</a>

This can be found in the comments.php template file, usually just above the comment form.

We now need to change the URL to log out from

<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout


<?php echo wp_logout_url(get_permalink()); ?>

The parameter in this function is then read as the redirect URL once the user has logged out, so they’ll be redirected back to the page where the link was clicked.

Note, this doesn’t apply to the meta area that is sometimes found in the sidebar. This link is already toggled between log in and log out (depending on your status) using the wp_loginout() function.

Next week I’ll explain the new features for comments and how to update your theme to work with these. For those who are not already aware, the new features are pagination and comment threading.

  1. WordPress 2.7 Theme Enhancements II
  2. WordPress 2.7 Theme Enhancements III