Blogging & WordPress Chris Gray on 24 May 2007 12:18 pm
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!







on 23 May 2007 at 3:39 am 1.Vince Cordic said …
Should come in handy Chris, when I setup a new blog I’ll install it and give it a try.
If you havn’t already you should submit it to the various wordpress plugin directories, might bring you some extra traffic.
Is http://www.nmediainteractive.com a new blog of yours?
on 24 May 2007 at 3:31 pm 2.Chris Gray said …
Vince,
Thanks for taking a look. Right now the functionality is a little limited but I am hoping to expand this plug-in to handle tweaks made in the sidebar and footer as well. I am also planning on taking your advice and submit it to a few plug-in directories (hopefully others might find it useful).
Yes, nMedia Interactive is a new blog of mine. I plan to post non-seo related information over there so as not to clutter this site with off-topic material. I also do some .NET development on the side and hope to use nMedia Interactive as a springboard for a few of my web development projects.
on 25 May 2007 at 4:40 am 3.Dennis Bjørn Petersen said …
This is exactly what I am looking for. The next time I install a new theme I will use your plugin Chris. Unfortunately I am such a PHP-amateur that I just place the code where ever I see fit and to fit the page, so now I have no chance of changing theme with out having to go over all my PHP-pages. Especially the Sidebar is very customised. It would be great if your plugin recognised the codes from different sites. Like you’ve already mentioned, MBL, Adsense, TLA, Feedburner and various commonly used plugins.
Great work and good reading!
on 25 May 2007 at 3:31 pm 4.Vince Cordic said …
Chris,
Perhaps you could implement tokens to define sections that will be tracked by the toggle tracker. So anything between something like and is picked up by the script.
on 26 May 2007 at 3:42 am 5.Vince Cordic said …
Oops should have known the tokens would be stripped out in my previous post.
on 27 May 2007 at 12:17 am 6.derek said …
Chris, this was something that was on my wishlist for Wendy’s project so I am happy to see this plugin. I’ve been kicking around the idea of updating my theme and will certainly be trying this out if I find a theme that I like.
If you’re ever in need of some assistance with the plugin, let me know and I can try to help.
on 27 May 2007 at 11:09 am 7.Chris Gray said …
@Dennis – Unfortunately the plug-in does not automatically transfer your tweaks from the current template to the plug-in (but that’s a great idea for a future release…I’ll see what I can do). I do believe that this plug-in should be able to handle any code tweak you enter in your page though…all you need to do is (manually) transfer your tweak from the template page to the plug-in and your customization should be available to your current theme from then on. Thanks for the great input! I’ll see what I can put together in the next couple of weeks.
@Vince - I have been looking into this a little further and I think you are absolutely right; tokens are the way to go. I am currently using the Akismet Contact Form that does just this. I am going to play around with this over the weekend and see if I can’t come up with something.
@derek – Thanks for taking a look…I hope you find it useful. I am just beginning to learn PHP so there is a lot of room for improvement. If there ends up being an interest in this plug-in I may end up moving it over to SourceForge or something…I will let you know.
on 28 May 2007 at 10:37 pm 8.Speedlinking - 28 May 2007 » Derek Semmler dot com said …
[…] SEO Ladder talks about a new plugin that I have been dreaming of to help make it easier to switch WordPress themes. Thank you Chris! When it is time for me to switch themes, I’ll be trying out your […]
on 30 May 2007 at 6:48 pm 9.26 Internet Marketing How To's for Every Level of Experience - eMoms at Home - Blogging and Internet Marketing for Home Based Entrepreneurs said …
[…] Chris on Theme Switching Systemization for WordPress […]