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
Go to your blog post in Squarespace
Click the ⚙️ Settings → Website Tools → Code Injection → Footer Code
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 defaultIf your date still looks incomplete, inspect the element (right-click → Inspect) to make sure the class name matches
Dates pulled from
datetime
attributes ormeta
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.