SlowBossa Posted March 2, 2021 Share Posted March 2, 2021 Site URL: http://chriscampos.com I would like to customize my foundry template so that when publishing a post it includes the full date, including the year. For example, right now the date on a post I made in October says "Oct 25" but I would like it to say "Oct 25, 2020". I have upgraded to a business plan to allow for customizations. I have also searched this forum and other sites for the right code to add as a "code injection" but haven't found anything that works. I would truly appreciate any help with this issue. Thanks!! Link to comment
Beyondspace Posted March 2, 2021 Share Posted March 2, 2021 2 hours ago, SlowBossa said: Site URL: http://chriscampos.com I would like to customize my foundry template so that when publishing a post it includes the full date, including the year. For example, right now the date on a post I made in October says "Oct 25" but I would like it to say "Oct 25, 2020". I have upgraded to a business plan to allow for customizations. I have also searched this forum and other sites for the right code to add as a "code injection" but haven't found anything that works. I would truly appreciate any help with this issue. Thanks!! Add this snippet into Settings->Advanced->Code Injection Foter <script> document.addEventListener('DOMContentLoaded', function() { var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; var pubdate = document.querySelectorAll(".entry-title [pubdate][datetime]"); for (var i = 0; i < pubdate.length; i++) { var d = pubdate[i].getAttribute("datetime"); var _date = new Date(d); var year = _date.getFullYear(); var month = months[_date.getMonth()].slice(0, 3); var date = _date.getDate(); pubdate[i].innerHTML = month + " " + date + ", " + year; console.log(month + " " + date + ", " + year); } }); </script> BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight 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
SlowBossa Posted March 2, 2021 Author Share Posted March 2, 2021 11 hours ago, bangank36 said: <script> document.addEventListener('DOMContentLoaded', function() { var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; var pubdate = document.querySelectorAll(".entry-title [pubdate][datetime]"); for (var i = 0; i < pubdate.length; i++) { var d = pubdate[i].getAttribute("datetime"); var _date = new Date(d); var year = _date.getFullYear(); var month = months[_date.getMonth()].slice(0, 3); var date = _date.getDate(); pubdate[i].innerHTML = month + " " + date + ", " + year; console.log(month + " " + date + ", " + year); } }); </script> Thank you so much for responding bangank36! I have added the code snippet to my site and I am getting a full date on my home page. However, I noticed one thing that isn't working as intended. The full date that is now showing is the day before the publication date. In this case, I published the post on Feb 28, 2021 but on my site it reads "Feb 27, 2021". Is there something that can be done to fix this? Thanks again!! Link to comment
Beyondspace Posted March 3, 2021 Share Posted March 3, 2021 10 hours ago, SlowBossa said: Thank you so much for responding bangank36! I have added the code snippet to my site and I am getting a full date on my home page. However, I noticed one thing that isn't working as intended. The full date that is now showing is the day before the publication date. In this case, I published the post on Feb 28, 2021 but on my site it reads "Feb 27, 2021". Is there something that can be done to fix this? Thanks again!! It just extract the date from the html, not modified anything. My best guess is maybe the timezone messed up the date. What is your timezone settings BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight 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
Archived
This topic is now archived and is closed to further replies.