How to add a visitor counter to WordPress

On a self-hosted WordPress site the cleanest way is a small plugin that adds code to the page header. It survives theme updates and takes a couple of minutes.

Self-hosted WordPress (WordPress.org)

Install a header and footer code plugin, for example WPCode (formerly Insert Headers and Footers). Open its Header & Footer screen, paste your BYOViral tracking code (in the dashboard, open Websites, choose your site and press Edit; the code is at the bottom of the page) into the Header box and save. That puts the code on every page, including posts, archives and WooCommerce pages.

Without a plugin

You can paste the code into your theme's header.php just above </head>, but do it in a child theme. Edits to the main theme are lost the next time it updates.

WordPress.com

On WordPress.com, adding your own scripts needs a plan that lets you install plugins. On those plans, install a header-code plugin and follow the steps above. Plans without plugins strip scripts from widgets and posts, so the code will not run; the free image hit counter still works there because it is just an image.

Caching and optimisation plugins

If you use a plugin that combines or delays JavaScript, exclude the BYOViral script from it, then clear the cache. Delayed scripts only run after the first click or scroll, which undercounts quick visits.

Check that it works

Open the site in a private window and watch the Realtime report. Logged-in WordPress admins are counted like anyone else, so test while logged out if you want a clean check.

Frequently asked questions

Does it slow WordPress down?

The script is under 1 KB and loads asynchronously, so it does not hold up the page.

Do I need a cookie banner for it?

BYOViral sets no cookies. Whether you need a banner depends on your other plugins and where your visitors are; see the guide on analytics without cookies.

Will it count WooCommerce pages?

Yes, every page that loads the theme header, including product, cart and checkout pages.

Try BYOViral free

Privacy-first analytics with no cookies and a real free tier.

Create your free account →