Since I’ve been asked, here’s a short recipe for adding a site counter to WordPress.

All the freely available site counters give you a piece of JavaScript. I personally used one from SiteMeter, but all the other sites work pretty similarly.

With WordPress, you can’t simply put it into index.html – it’s template based. You need to embed this code in a template that is always displayed – for most WordPress themes, that’s the SideBar.

So how do you edit it? Log in as site adminstrator. In the Administration page, go to the Presentation Page and select the Theme Editor. Select the Sidebar template. It will show up as a PHP file – but don’t worry. It really is HTML with a bit of PHP thrown in for good measure.

The whole sidebar is usually embedded in a single <div> tag – find the end of that tag. Right before the end of that tag, paste your javascript that you got for the side counter. That’s all there is too it.

On some WP installations, you might not be able to edit your themes through the web interface – in this case, below the textbox, you will see the string “If this file was writable you could edit it.

That means you need to actually log into the shell for your account and modify the file there. Thankfully, the web page gives you the path to the file relative to the WP installation directory as a title above the text box – so just cd to there, and edit the file. Et voila, your site counter is active!

Commentary

  1. green LA girl wrote on 08. Dec 2005

    How would I survive on the blogosphere without you? Thanks for the tip!

  2. epepota wrote on 04. May 2008

    I can’t find the sidebar to edit it. I want to add a counter but I haven’t been able to. HELP!

  3. Matte wrote on 03. Jul 2008

    And how do you do it on wordpress.org?

    Or how do you set it up under google analytics? Google Webmasters? Hmmm… all those questions? :)

  4. Robert 'Groby' Blum wrote on 08. Jul 2008

    I’m afraid these are a few to many to answer in a single blog post ;)

    (If you need help with any specific one, let me know. I’ll be happy to do a small screencast if I can)

  5. Ollie wrote on 15. Jul 2008

    I’m stuck with wordpress.org too. Any ideas?

  6. Olliver wrote on 15. Jul 2008

    nevermind, you just select footer instead of sidebar and put it above the tag

  7. sugenk wrote on 22. Nov 2008

    thanks for your tips!

  8. keith wrote on 29. Oct 2009

    1 have 24 images and want a counter on each to see which image is most popular. any suggestions?