How to Make WordPress Theme Changes Easy with Widgets
20
Comments
Have you ever thought to yourself, “I’d like to try out a new theme, but I’ve spent so much time putting custom code (counters, plugins etc) into my current theme, that it’s too much work to switch?”
This WordPress tip is designed to make it much easier to change themes, which will benefit established bloggers doing an upgrade, but especially new bloggers who are just starting out and experimenting with different looks for their blog.
One day while playing around with my site and inserting my StatCounter code into my footer, I had a thought, “What if I stuck this into a widget?”
I gave it a try and sure enough it worked, the counter kept tracking my stats. Then I tried it with Google Analytics and everything else that I had cluttering my footer.php file and they all worked.
How To Setup A Stats Widget
The process is really simple. In short, we just need to grab all the html or JavaScript code that you have added to your theme’s footer and place it into a WordPress widget.
What You Can Place in a Widget
- Google Analytics
- Stats and counters
- My Blog Log tracking code
- Hittail or similar code
- Quantcast
- Any other code that doesn’t actually display on your page
What Won’t Work
- Custom php code (anywhere you see
<?php ?>tags) - If you have AdSense in your footer, don’t move it.
Let’s get started…
Step 1 - Remove the Code from Your Footer
Go to your blog’s dashboard and navigate to Presentation / Theme Editor. Scroll down the list of files on the right hand menu and click on “Footer” (in some cases it will be called footer.php).
Search around in that file and cut out (remove) all the code snippets that you have added to it. Chances are they will use the <script> tag. I recommend putting them all into Notepad temporarily.
After they are all removed, then click “Update File” to save the footer file without your code in it.
Do step 2 right away so you don’t miss any stats.
Step 2 - Put the Code into a Widget
First you’ll need to make sure your blog has widgets available. WordPress 2.2 and later has them by default but with any previous version of WordPress, you’ll need to download and install the Widgets plugin. Or even better, upgrade your WordPress installation.
Navigate to the Presentation / Widgets page.
Drag a “Text” widget from the “Available Widgets” panel, up to one of your columns. I prefer to put in at the bottom of the right hand column. If there aren’t any Text widgets in the “Available Widgets” panel, then create a new one, in the box just below that panel.
Click the little configuration box on the right hand side of the new text widget to pop open the widget entry box.
Copy and paste all the code the you removed from your footer into the body of the box. Leave the title blank (if you put anything in there, it will show up on your page, which you don’t want).
Close the widget by clicking the “X” at the top right corner.
Click “Save Changes” to update your widget settings.
That’s it. I recommend that you take a look at your stats counter (and any other services) to make sure they are working and tracking visitors. All it takes is a missed “>” in the copy and paste process and they won’t function correctly.
Now when you want to change your theme, you don’t have to worry about forgetting to move your counter and other tracking codes.
One Small Step Towards Theme Independence
This tip will allow you to move one step closer to having theme freedom. My ultimate setup for WordPress would be to never have to add code into the theme files manually.
This would mean that if a new version of your theme is released or if you change your theme you won’t need to migrate any code.
It seems to me that more and more plugin designers are climbing on the bandwagon and creating plugins that integrate automatically into posts and pages without needing to add the code manually.
This has been just a tiny tip that can hopefully save you some headaches in the long run make blogging easier and more fun.
Jon Symons blogs about Internet business and has installed or helped others setup, hundreds of WordPress blogs. His latest project is a WordPress installation service.












Sparkplugging Founder Wendy Piersall is dang passionate about helping people start & grow a business while maintaining life balance (somehow).
Dawud Miracle has one focus: to help you get it. The it? How your website, and blog, can change the way you do business. You can find out more at 

Nice write-up Jon and welcome to the guest blogging team
Thanks Glen, and thanks to Wendy for using my tip.
Good idea Jon. I thought I’d mention that there is a plugin that will allow you to even put php code into a widget. You have to be on WP 2.2.1 (small bug in 2.2 causes it not to work, but it was fixed in the next verison). I have used this plugin and it works great!
Hey Randa, that’s a great plugin too. I thought of mentioning it, but I can be long-winded enough without tossing too many ideas into a post
Speaking of themes, what happened to Wendy’s, I am seeing the default wordpress theme?
GRRRrrrrr….. THANKS George! I’m working on updating my theme and we’re using a theme previewer plugin to see the changes live on the back end. But every now and then it seems to forget what the heck is going on and goes back to the default!
You are welcome. I figured it was something like that. I had something similar happen to me before when I was messing with my theme.
Great tips.Thats what i call productive blogging.
I have done this very thing for a very long time. It does work perfectly. I can change themes on a whim almost. I just change over two codes in the footer and the meta tags in the headers. I go in and ad my signature into the base of each post on the index page and I am changed over.
I have gotten fond of this theme now though, so no changes are expected soon, but it is easy enough.
Okay- I’m new to all of this…
but stumbled on ‘Canvas’ a week or so ago - and it sounds like the same kind of thing. It is a plug in that can be used with KIWI theme (although there are instructions for using it with any theme, I think)…
Is Canvas the same kind of thing? Here is the link:
http://freshpursuits.com/canvas/
Jenni
Jenni, Canvas is a tool to change the look or style of your blog. WordPress widgets, which this tip uses, are for adding functions of code or tools to your sidebar without having to edit code. In a sense both are designed to allow changes without touching code, but the type of changes that they make are quite different.
This answered my questions rather nicely I was wondering what I needed to do in order to someday change themes but now I have gotten attached to skittlish so I think it will be my theme for a little while longer anyway.
Thankyou ,
What a fantastic tip, I need to change my theme and was dreading all the coding I was going to have to do. This is a great start- looks like it could be a good series Jon and Wendy. Still not sure how to create a new text widget- I have the option of 9 text widgets which I seem yo have used up?
Any help gratefully accepted
Hi Suzie, I took a look at your site and it doesn’t look like you have all 9 Text widgets in use. After you have created 9, are there really none in the “Available Widgets” panel?
If so, then I suspect that some of the ones you have dragged up into your columns are empty and would be available to put your stats code into. As a last resort, you could put your stat code into a Text widget that is already being used, since it will not show up on your site.
Good idea. It is always a nightmare when you switch themes.
Randa:
Great plugin. I’ve been looking for something like that.
Great post. This is just what I was looking for. I’ve been wanting to do something with widgets and my stats and now I know how.
Thanks.
Wow! This is exactly what I am looking for and you presented it so clearly! Thank you so much!
Very good idea. I’ve actually been using a plugin created by Chris Gray at SEOLadder.com that does a similar thing, I completely overlooked this as a possibility.
Wendy, have you ever investigated using XAMPP to setup a development environment for your blog. I linked a post above that I wrote about using XAMPP to test site changes.