Blogging & WordPress Chris Gray on 24 May 2007
WordPress Theme switching made easier
One of my favorite features of the WordPress platform is having the ability to drastically change the look and feel of my blog with literally the click of a button. Since release 1.5, WordPress users have had the ability to quickly edit and deploy blog themes with little or no understanding of HTML or PHP.
What is a Theme?
A theme is basically a collection of PHP, CSS, JavaScript, and image files that make up the presentation layer of your blog. The WordPress theme system separates these graphical elements from the “guts” of the WordPress engine, allowing you to “skin” your blog without having to know the inner workings of WordPress (or HTML for that matter).
With literally hundreds of websites dedicated to the development of free WordPress themes, I no longer need to spend hours developing that new Graphical User Interface (GUI) and am free to concentrate on developing content.
The problem with switching Themes
Themes are great but can present a new set of issues. If you are like me, you may not be satisfied with a stock theme and tend to do a little “tweaking” after the fact. At a minimum, I always add a number of tracking scripts (Google Analytics, MyBlogLog, BlogCatalog) to the head section (<head></head>) of my blog allowing me to track site usage. The problem with “tweaking” is that every time I change templates I need to transfer these “tweaks” to my new template. This process is not that difficult but can be rather time consuming and can also lend itself to error.
My solution
With that being said, I thought it was time to investigate an automated solution. Another great WordPress feature is the ability to create plug-ins. A plug-in is essentially a small PHP script that extends the functionality of the WordPress platform. I searched for a plug-in that could move my tweaks to a new theme upon theme activation but was unable to find anything remotely close…so I decided to roll my own solution.
I decided to create a plug-in that would take all of my tracking code (placed in the head section of my blog pages) and store it in one place. In this case I am storing it in the WordPress database. From there I hooked into the WordPress “Loop” so that my tracking code would show up on each page. I also added a feature that allows you to turn this tracking code on/off. This feature is useful if you have a sandboxed WordPress installation (used to test template changes away from your production server) and do not want to skew your stats by repeated testing.
Screen Shot![]()
Download
If you are interested in trying this plug-in you can get it here:
Download the ToggleTracking 1.0 WordPress Plug-in
Room for improvement
This was my first attempt at creating a WordPress plug-in so there is plenty of room for improvement. While this plug-in handles code placed in the head it does not handle tweaks elsewhere in the page (i.e. sidebar, or footer). I plan on extending it to accommodate these areas and possibly even include functionality to handle ads such as Text Link Ads or AdSense. Drop me a line if you find it useful or have a suggestion.
Note: This post was sparked by Wendy Piersall’s “Wish List Research Project” over at eMomsAtHome.com. Stop by her blog and check out some of the cool things she is doing to help budding entrepreneurs!








