Content Counter Plugin
Introduction
The Content Counter plugin adds shortcodes that display content counts anywhere on your Publii site. Posts, pages, tags, authors - drop a shortcode into your content or template, and it gets replaced with the actual number during rendering.
This happens at build time. The plugin scans your site's content structure, counts the relevant items, and replaces every shortcode in the final HTML. Your visitors see static numbers - no JavaScript, no API calls, no extra requests.
You get control over what gets counted, how labels are formatted, and how the output is styled. The plugin handles meta tags and JSON-LD separately from visible content, so your SEO stays clean regardless of how you use the shortcodes.
Enabling the Plugin
Open Publii and head to the Tools & Plugins section. Find Content Counter in your plugin list and flip the switch at the bottom-left corner of its tile to turn it on.
Once enabled, you'll see configuration options and a reference card listing all available shortcodes. The plugin works immediately with default settings - just start adding shortcodes to your content.
Available Shortcodes
Basic counts
These shortcodes output a single number - the count of the specified content type.
[pcc=posts]- total number of published posts. This is the most common shortcode. Use it in footers, about pages, or anywhere you want to show how much content your site has.[pcc=pages]- total number of published pages. Counts static pages like About, Contact, or any custom pages you've created.[pcc=total]- combined count of posts and pages. Useful when you want a single number representing all content on the site.[pcc=featured]- number of posts marked as featured. Only counts posts, not pages.
Tag and author counts
These shortcodes count posts belonging to a specific tag or written by a specific author. You can reference tags and authors by their slug (the URL-friendly name) or by their numeric ID.
[pcc=tag name=tutorials]- number of posts in the tag "tutorials" (by slug). The slug is the URL-friendly version of the tag name - lowercase, hyphens instead of spaces. You can find it in the tag's URL on your site.[pcc=tag id=5]- same thing, but using the tag's numeric ID. IDs are stable - if you rename a tag, the ID stays the same. Slugs are more readable but change when you rename a tag.[pcc=author name=olivia-reynolds]- number of posts by the author "olivia-reynolds" (by slug).[pcc=author id=3]- same thing, using the author's numeric ID.
If a tag or author doesn't exist (wrong slug or ID), the shortcode is left as-is in the output. This makes it easy to spot typos - you'll see the raw shortcode on your page instead of a number.
Label parameter
Adding label to a tag or author shortcode includes the tag or author name alongside the count. The position of label in the shortcode controls the output order.
Label before the name/id parameter - name first:
[pcc=tag label name=tutorials]→ Tutorials: 5[pcc=author label id=3]→ Olivia Reynolds: 12
This format works well for headings, sidebar widgets, and data labels. The separator between the name and the count (colon by default) is configurable in the plugin settings.
Label after the name/id parameter - count first:
[pcc=tag name=tutorials label]→ 5 Tutorials[pcc=author id=3 label]→ 12 Olivia Reynolds
This format reads naturally in sentences. No separator is used - just a space between the count and the name. For example:
This site has [pcc=tag name=tutorials label] available.
→ This site has 5 Tutorials available.Shortcode format variations
All shortcodes support three separator formats between pcc and the type:
[pcc=posts]- equals sign (recommended)[pcc-posts]- hyphen (alternative)[pcc=posts]- HTML entity (generated automatically by Publii's WYSIWYG editor)
You don't need to worry about the third format. Publii's editor sometimes encodes the = character as = behind the scenes. The plugin handles this automatically - just type [pcc=posts] in the editor and it works.
Plugin Configuration
General
These settings control what gets counted and how labels are formatted.
Include hidden posts and pages - when enabled, posts and pages with "hidden" status are included in all counts. Off by default. Most sites want to count only published, visible content. Turn this on if your hidden posts are still meaningful for your total count - for example, if you use "hidden" to keep posts out of listings but they're still accessible via direct link.
Label separator - the character placed between the name and the count when using label-before mode (e.g.,
[pcc=tag label name=tutorials]). A space is always added after the separator, before the count. Choose from built-in presets::(colon) - Tutorials: 5 (default)-(dash) - Tutorials - 5|(pipe) - Tutorials | 5→(arrow) - Tutorials → 5- (none) - Tutorials 5
- Custom - enter any character or string you want
This setting only affects label-before mode. Label-after mode always uses a simple space between the count and the name.
Custom separator - your own separator character(s). Only appears when "Label separator" is set to "Custom." You can enter anything here - a single character, a word, an emoji, whatever fits your design.
HTML Output
These settings control the HTML structure of the generated output.
Wrap output in <span> tags - when enabled, every shortcode output gets wrapped in
<span>elements with CSS classes for styling. Off by default. With this disabled, shortcodes are replaced with plain text - just numbers and names, no HTML.When enabled, the output structure depends on the shortcode type:
Basic shortcode:
<span class="pcc pcc-posts">42</span>Tag/author shortcode with label before:
<span class="pcc pcc-tag"><span class="pcc pcc-label">Tutorials:</span> 5</span>Tag/author shortcode with label after:
<span class="pcc pcc-tag">5 <span class="pcc pcc-label">Tutorials</span></span>Custom CSS class - the base class applied to all generated
<span>elements. Default ispcc. Only appears when "Wrap output in <span> tags" is enabled. The plugin automatically adds type-specific modifiers:pcc-posts,pcc-pages,pcc-total,pcc-featured- for basic countspcc-tag,pcc-author- for tag and author countspcc-label- for the name portion inside label shortcodes
If you change the base class to, say,
counter, the modifiers follow:counter-posts,counter-tag, etc.
Using the Plugin
In the post or page editor
Just type the shortcode directly in your content. Works in both the WYSIWYG editor and the source code editor.
We have published [pcc=posts] articles and [pcc=pages] pages so far.After rendering, your visitors see:
We have published 56 articles and 14 pages so far.In Handlebars templates
Shortcodes work in any .hbs file in your theme. Place them wherever you need dynamic counts - headers, footers, sidebars, post templates.
<div class="site-stats">
<p>[pcc=posts] articles published</p>
<p>Browse our [pcc=tag label name=tutorials]</p>
</div>Styling with CSS
Enable "Wrap output in <span> tags" in the plugin settings, then add CSS rules targeting the generated classes. You can add styles via Publii's built-in Custom CSS tool (found in Tools & Plugins):
.pcc {
font-weight: bold;
color: #2563eb;
}
.pcc-label {
font-weight: normal;
color: #666;
}How the plugin handles <head> vs <body>
If you place a shortcode in post content that Publii also uses to generate meta descriptions or JSON-LD structured data, the plugin handles it correctly. Shortcodes inside <head> are always replaced with plain numbers - no <span> tags, no HTML. Only shortcodes inside <body> get the optional HTML wrapping.
This means you can safely use shortcodes at the beginning of a post without worrying about HTML markup leaking into your Open Graph descriptions, meta tags, or search engine previews.
Common Configuration Examples
Simple site counter in footer - add
[pcc=total] articles and countingto your footer template or a page that serves as your homepage. Leave all settings at default. Done.Tag page with labeled count - use
[pcc=tag label name=your-tag]in a heading or intro paragraph. The colon separator works well for this. Result: "Photography: 23".Natural sentence with count - use label-after:
Browse our [pcc=tag name=tutorials label] articles. Set the label separator to "(none)" if you're only using label-after mode. Result: "Browse our 12 Tutorials articles".Author bio with post count - in your author template or bio section, use
[pcc=author name=your-slug label]to show something like "23 Olivia Reynolds" - or flip it to[pcc=author label name=your-slug]for "Olivia Reynolds: 23".Styled counters with custom classes - enable span wrapping, set a custom class like
stats, and style with CSS. Each count type gets its own modifier (stats-posts,stats-tag, etc.), so you can color-code different counters or add different font sizes.Including hidden content - if you use "hidden" status for draft-like posts that are still accessible via direct link, enable "Include hidden posts and pages" so your counts reflect the full library.
Troubleshooting
Shortcode appears as raw text
Check these:
- Is the plugin enabled?
- Is the shortcode spelled correctly? It must start with
[pcc- case-sensitive, no spaces before the equals sign. - For tag/author shortcodes: does the slug or ID actually exist? The plugin leaves unmatched shortcodes as-is, so a typo in the slug will show the raw shortcode on the page.
- Make sure you're looking at the generated site, not the editor preview. The plugin runs during rendering, not in the editor.
Count seems wrong
Verify:
- Is "Include hidden posts and pages" set the way you expect? Hidden posts are excluded by default.
- For tag counts: check that posts are actually assigned to that tag. A post with no tags won't appear in any tag count.
- For author counts: make sure posts are attributed to the correct author.
- Remember that counts update only when you generate your site. If you've added posts since the last build, generate again to see updated numbers.
HTML appears in meta tags or social previews
This shouldn't happen - the plugin replaces shortcodes in <head> with plain numbers only. If you're seeing HTML in meta descriptions, make sure you're using the latest version of the plugin. Earlier versions didn't separate head and body processing.
Label separator doesn't work
The separator only applies to label-before mode ([pcc=tag label name=...]). Label-after mode ([pcc=tag name=... label]) always uses a simple space. If you've changed the separator and don't see the change, try disabling and re-enabling the plugin, or re-select the separator in plugin settings and generate again.
Final Thoughts
The Content Counter plugin gives you dynamic numbers on a static site without touching theme code or adding client-side scripts. Configure it once, add shortcodes where you need them, and the numbers update every time you build.
Most users only need the basic shortcodes - [pcc=posts] and [pcc=total] cover the majority of use cases. Tag and author counts with labels are there when you need more detail, and the HTML wrapping option is available when you want precise styling control.
The plugin never stores data. Everything is calculated fresh during each build, so you can experiment with settings freely. Change a separator, toggle hidden content, switch CSS classes - just generate again and see the result.