Pocamuffin Posted October 14, 2021 Share Posted October 14, 2021 Site URL: http://alextreadway.co.uk/journal Does anyone know how to change the date format on blog pages? Right now it's: Wednesday 10.13.21 I'm in the UK so would be much better like this for example: 13th October 2021 Is there a fix somehow? Thanks Alex Link to comment
Pocamuffin Posted October 14, 2021 Author Share Posted October 14, 2021 So after some experimenting with other posts I've solved this. Solution here. Ad this code to settings/advanced/code injection See pic attached shows result <!-- Fix inconsistent blog date format on Squarespace 7.1 template --> <!-- Squarespace Forum 03-08-2021 --> <script src="https://stevenlevithan.com/assets/misc/date.format.js"></script> <script> document.addEventListener('DOMContentLoaded', function() { var dateformat = "dd mmmm yyyy"; var pubdate = document.querySelectorAll("time[datetime], time[pubdate], time.blog-meta-item--date"); for (var i = 0; i < pubdate.length; i++) { var d = new Date(pubdate[i].getAttribute("datetime") || pubdate[i].innerText); if ( pubdate[i].classList.contains('blog-meta-item--date') ) { d = new Date(document.querySelector('[itemprop="datePublished"]').getAttribute("content").split("T")[0]); } pubdate[i].innerHTML = d.format(dateformat); } }); </script> Beyondspace and tuanphan 2 Link to comment
Beyondspace Posted November 7, 2021 Share Posted November 7, 2021 As additional info, you can edit any other format by editing the line var dateformat = "dd mmmm yyyy" BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox) 🗓️ Delivery Date Picker (Squarespace Date format) 💫 Animated Buttons (Referral URL) 🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations) 🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment