How to Make WordPress Theme Changes Easy with Widgets

Read more about: Business Blogging, Site Tools + Tips

20
Comments

Guest Author Jon SymonsHave 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.

Bookmark it for Later or Share it With Your Friends... These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • StumbleUpon
  • del.icio.us
  • Ma.gnolia
  • NewsVine
  • Sk-rt
  • Sphinn
  • TwitThis
  • YahooMyWeb
Read more about Business Blogging, Site Tools + Tips

Support the Sparkplugging Community

These ads are only available to readers like you!

Learn more here

If you liked this article, please...

Subscribe Via Email Subscribe Via RSS

Or read these related articles...

Discussion

What do you think? Leave a comment. Alternatively, write a post on your own weblog; this blog accepts trackbacks [Trackback URL]. Comment Policy

Comments

1. On August 14th, 2007 at 9:07 am, Glen said:

Nice write-up Jon and welcome to the guest blogging team ;)

2. On August 14th, 2007 at 9:21 am, Jon said:

Thanks Glen, and thanks to Wendy for using my tip.

3. On August 14th, 2007 at 9:34 am, Randa Clay said:

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!

4. On August 14th, 2007 at 9:42 am, Jon said:

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 :)

5. On August 14th, 2007 at 10:27 am, George said:

Speaking of themes, what happened to Wendy’s, I am seeing the default wordpress theme?

6. On August 14th, 2007 at 10:40 am, Wendy Piersall said:

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! :roll:

7. On August 14th, 2007 at 11:46 am, George said:

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.

8. On August 14th, 2007 at 11:54 am, Blogger Whale said:

Great tips.Thats what i call productive blogging.

9. On August 14th, 2007 at 1:30 pm, Jennifer said:

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.

10. On August 14th, 2007 at 3:53 pm, Jenni said:

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

11. On August 14th, 2007 at 4:03 pm, Jon said:

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.

12. On August 14th, 2007 at 4:41 pm, Joe Cheray said:

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.

13. On August 14th, 2007 at 6:23 pm, Suzie Cheel said:

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

14. On August 14th, 2007 at 7:18 pm, Jon said:

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.

16. On August 15th, 2007 at 9:58 am, Jenny said:

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.

17. On August 16th, 2007 at 9:42 pm, Shine With Grace said:

Wow! This is exactly what I am looking for and you presented it so clearly! Thank you so much!

18. On August 17th, 2007 at 9:09 am, derek said:

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.

Mentions on other sites...

  1. Adding Google Analytics Code to Your WordPress Site on August 30th, 2007 at 9:07 am
  2. Speedlinking - The One Where It’s All About Me on September 17th, 2007 at 1:19 pm


Leave a Reply