Friendly reminder to update your website's footer

Friendly reminder to update your website's footer

Posted Jan 10, 2021, 5:36 AM UTC

177
joshmitchell386:cs:•

It’s amazing more websites don’t just use: (for example) 1996-<?php echo date("Y"); ?> to always display the correct year and eliminate the need to update every year

5
djo0o0•

I just started a HTML course to add to my Java courses and was going to ask "can't you just add some function to update a variable every time it needs ". So here's my like

4
joshmitchell386:cs:•

My example was assuming the use of php (so file would have to end in .php), if you wanted to do it in javascript and html only, I guess you'd use something like:

<p>1996-<span id="currentYear"></span></p>

<script>

document.getElementById("currentYear").innerHTML = new Date().getFullYear();

</script>

Considering how easy it is to automate this and the wide variety of ways to do it, it's surprising how many big websites don't use this :)

2
djo0o0•

Nice , thank you for the example added it to my "cool thing to use.txt" file :D

2
joshmitchell386:cs:•

Happy to help :)

2
altf4tsp•

I personally think the server backend would be better for this both as it doesn't rely on the client and also means the client cannot tell it is being updated automatically

2
joshmitchell386:cs:•

Using php and server side updating is the preferred way of doing it and would be what I would use... but if you wanted to do it without learning php then that would be the script you’d use

1
[deleted]•

[deleted]

1