Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

With foundry template, how can I customize the date format to include the year?


SlowBossa

Question

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!!

Example.jpeg

Link to post
  • Answers 3
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

Popular Posts

Add this snippet into Settings->Advanced->Code Injection Foter <script> document.addEventListener('DOMContentLoaded', function() { var months = [ 'January', 'February',

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 pos

Posted Images

3 answers to this question

Recommended Posts

  • 0
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!!

Example.jpeg

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>

image.png.af817370cb4c57fd05815ba995ef75cd.png

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, 360 Degree Photo block, Seperator Block (SVG Shape divider for sections)
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to post
  • 0
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!!

Example2.jpeg

Link to post
  • 0
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!!

Example2.jpeg

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

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, 360 Degree Photo block, Seperator Block (SVG Shape divider for sections)
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...