Adding a visitor counter to WordPress takes a few minutes once you know where your site accepts JavaScript. This guide covers the three common places to install GNRCounter on a self-hosted WordPress site: a Custom HTML block or widget, the site footer in a block theme, and a code-snippet plugin for site-wide hidden tracking. It also explains the WordPress.com plan limits and the caching settings that most often stop a counter from appearing.
Before you start: which WordPress do you have?
There are two products called WordPress, and the difference matters for counters.
- Self-hosted WordPress (WordPress.org): you install WordPress on your own hosting. Administrators can add JavaScript to blocks, widgets, theme files or plugins.
- WordPress.com: a hosted service. On plans that do not allow plugins or custom code, script tags are removed when you save, so a JavaScript counter cannot run. Check your plan’s custom-code and plugin features before you try the steps below.
You also need a user role that is allowed to save unfiltered HTML. On a normal single site this is the Administrator role (and usually Editor). On a multisite network, only a Super Admin can save script tags. If you paste the code and it disappears after saving, your role or plan is the likely cause.
1. Create your counter and copy the code
Open Create your free counter, enter your domain without a page path, choose your country, timezone and counter language, then pick Text for a visible counter or Hidden for tracking without a display. After you submit the form, copy the generated embed code and save your private management link somewhere safe. The code looks like this, with your own ID in place of the placeholder:
<!-- GNRCounter -->
<script src="https://gnrcounter.com/counter.php?accId=YOUR_COUNTER_ID"></script>
<noscript><a href="https://gnrcounter.com">Free hit counter</a></noscript>
<!-- End GNRCounter -->
A text counter is drawn exactly where the script sits in the page, so the place you paste the code is also the place the numbers will appear. Hidden tracking has no display, so for hidden mode you only need to make sure the code loads on every page you want to measure.
2. Option A: a Custom HTML block in the footer (block themes)
Most recent default themes, such as Twenty Twenty-Four and Twenty Twenty-Five, are block themes. Their header and footer are template parts that you edit in the Site Editor, and a change there applies to every page that uses that footer.
- Go to Appearance → Editor and open Patterns (or Template Parts in some versions), then select your Footer.
- Click the plus icon where you want the counter, search for Custom HTML and add the block.
- Paste the full GNRCounter code into the block. Use the block’s Preview tab to check that it renders rather than showing the code as text.
- Click Save and confirm that you are saving the footer template part.
Place a visible counter in a narrow column or a row of its own so it does not push other footer content around. On mobile, footers usually stack into one column, so check the result on a phone-sized screen as well.
3. Option B: a Custom HTML widget (classic themes)
Classic themes use widget areas such as a sidebar or footer columns. If your theme has Appearance → Widgets, you are using widget areas.
- Open Appearance → Widgets.
- Choose the widget area where the counter should appear, for example Footer 1 or Sidebar.
- Add a Custom HTML block or widget. Do not use a Paragraph or Text widget, because those may print the code as text.
- Paste the code, give the widget an optional title such as “Visitors”, and click Update.
A sidebar widget appears only on templates that show that sidebar. Many themes hide the sidebar on full-width pages or on mobile, so a sidebar counter is not always a site-wide counter.
4. Option C: a code-snippet plugin for hidden tracking
If you chose hidden tracking and want it on every page, a header-and-footer code plugin is often the simplest route. Plugins such as WPCode let you add a snippet to the site footer without editing theme files.
- Install and activate the plugin from Plugins → Add New.
- Open its header and footer settings and paste the GNRCounter code into the Footer box.
- Save, then open several different page types (home, a post, a page, an archive) to check that the code is present.
Code added through a footer hook is printed near the end of the page. That is fine for hidden tracking. For a visible text counter it would appear at the very bottom of the page, below your footer, which is rarely where you want it. Use Option A or B for a visible counter.
5. Editing theme files: only with a child theme
Experienced users sometimes paste the code into the theme’s footer.php. If you do this, use a child theme. Changes made directly in a parent theme are overwritten when the theme updates, and the counter will silently disappear. Block themes do not use footer.php for their footer, so Option A is the right approach there.
6. Caching and optimisation plugins
Performance plugins are the most common reason a counter works in the editor preview but not on the live site. Features to look at include:
- Delay JavaScript execution or load JavaScript on user interaction: the counter waits until a visitor scrolls or clicks, so some visits are never recorded.
- Defer JavaScript or combine/minify JavaScript: a text counter is written at the script’s position while the page loads, and moving or deferring the script can prevent it from rendering.
- Page cache: after adding the code, clear the cache so visitors receive the updated page.
If you use one of these features, add gnrcounter.com to the plugin’s exclusion list for delayed or deferred scripts, then clear all caches, including any CDN cache.
7. Check that it works
Open your site in a private browser window so you see it as a visitor would. For a text counter, check the display on desktop and mobile. Then open your report link and look at today’s recorded activity with the correct timezone selected. If you use a browser extension that blocks trackers, your own visit may not be recorded; that alone does not mean the installation failed.
Troubleshooting checklist
- The code shows as text on the page: you used a Paragraph or Text block instead of Custom HTML.
- The code disappears after saving: your user role or WordPress.com plan does not allow scripts.
- The counter shows on some pages only: the widget area or template part is not used by every template.
- Nothing appears after a cache plugin was installed: exclude the counter script from delay and defer settings and clear the cache.
- The counter appears twice: the code was added in two places, for example a widget and a footer plugin. Keep one copy.
If you are still stuck, contact us with the public address of a page that should contain the code. Never send your private management link.
Privacy and next steps
Mention the counter in your site’s privacy notice and obtain consent where the law requires it before non-essential tracking starts. Our privacy policy describes the data the counter processes. Once data is coming in, read unique visitors vs page views to interpret the first numbers, and our traffic sources guide to see where your WordPress visitors come from.