Format Your Blog Post Dates to Include the Year (Automatically)

Squarespace blog templates sometimes only show the month and day of publication — for example:

April 26

That might be fine for casual blogs, but if you’re writing content that people cite, reference, or revisit over time, not including the year can create confusion. This is especially important for academic-style writing, evidence-based content, or anything evergreen.

What This Code Fixes

This small snippet of JavaScript scans your blog posts for hidden or incomplete date elements. It checks if there’s a <time class="dt-published"> element on the page, grabs the full date (from either the tag or its fallback metadata), and reformats it into a standard, complete date like:

April 26, 2024

It runs automatically once the page loads, and works on most Squarespace templates.

How to Use It

  1. Go to your blog post in Squarespace

  2. Click the ⚙️ SettingsWebsite ToolsCode InjectionFooter Code

  3. Paste the following code into the Footer field:

<!-- 📅 Format Published Dates -->
<script>
document.addEventListener("DOMContentLoaded", function () {
  document.querySelectorAll("time.dt-published").forEach(el => {
    const dateText = el.getAttribute("datetime") || el.textContent.trim();
    const metaDate = document.querySelector('meta[itemprop="datePublished"]');
    const year = metaDate ? new Date(metaDate.content).getFullYear() : new Date().getFullYear();
    const fullDate = new Date(`${dateText} ${year}`);
    if (!isNaN(fullDate)) {
      el.textContent = fullDate.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" });
    }
  });
});
</script>

That’s it. Once saved, the year will be automatically appended to blog post dates — no need to manually edit anything.

Troubleshooting

  • This only works if your template uses <time class="dt-published"> — which most Squarespace blogs do by default

  • If your date still looks incomplete, inspect the element (right-click → Inspect) to make sure the class name matches

  • Dates pulled from datetime attributes or meta tags are usually accurate, but always double check older posts if the content was imported

Optional Tweaks

Want a different format? You can adjust the toLocaleDateString() line:

{ year: "numeric", day: "numeric", month: "short" }

... would give you something like:

26 Apr, 2024

Simply Put

This is a quiet but important upgrade — especially if your content is meant to last. Adding the year gives your posts more credibility and clarity, especially when readers return months (or years) later.

Is This Free to Use?

Personal use is free forever.
If you’re using this tool on your own blog, portfolio, or personal Squarespace site, you don’t need to pay — enjoy it freely.

Commercial use requires a one-time license.
If you’re a developer, agency, or using this on a client project or monetized site, please purchase a commercial license. It helps support ongoing development and gives you peace of mind.

One-time cost: £49.99 (normally £79.99)
Covers unlimited client sites, all current tools, and future updates.

👉 Learn more or buy a license here

JC Pass

JC Pass is a specialist in social and political psychology who merges academic insight with cultural critique. With an MSc in Applied Social and Political Psychology and a BSc in Psychology, JC explores how power, identity, and influence shape everything from global politics to gaming culture. Their work spans political commentary, video game psychology, LGBTQIA+ allyship, and media analysis, all with a focus on how narratives, systems, and social forces affect real lives.

JC’s writing moves fluidly between the academic and the accessible, offering sharp, psychologically grounded takes on world leaders, fictional characters, player behaviour, and the mechanics of resilience in turbulent times. They also create resources for psychology students, making complex theory feel usable, relevant, and real.

https://SimplyPutPsych.co.uk/
Previous
Previous

Customize Author Links on Your Squarespace Blog Posts

Next
Next

Add a Sliding Summary Drawer to Your Squarespace Blog Post