Hello, I’m trying to add this to my page:
“Published: (Current Date - 2 DAYS)”
Can someone advise my on how to accomplish this on F+ ?
Thanks
Hello, I’m trying to add this to my page:
“Published: (Current Date - 2 DAYS)”
Can someone advise my on how to accomplish this on F+ ?
Thanks
Hi there please add a custom HTML Element to your page then press edit:
<p class="publishDay"></p>
Finally, go to Custom Codes > Custom JS Body
Paste the following:
<script> var d = new Date(); var dplus = new Date(); dplus.setDate(d.getDate()-2); const options = { weekday: 'short', month: 'short', day: 'numeric' }; let ships = document.querySelectorAll(".publishDay"); ships.forEach(d => { d.innerHTML = '"Published ' + dplus.toLocaleDateString('en-US', options) + generateTh(dplus.getDate()) + '"'; }) function generateTh(d){ let ar = String(d).split(''); if (ar[ar.length-1] == 1 && d != 11) return 'st'; else if(ar[ar.length-1] == 2 && d != 12 && d != 13) return 'nd'; else if(ar[ar.length-1] == 3) return 'rd'; return 'th'; } </script>