January 1, 2016

Auto Update Copyright Year In Website Footer

Every year I have to go through my various WordPress blogs and update the copyright year in the footer. For example, Raving Roo started in 2013, so I display the copyright as “2013 – current year”. Well, why do something manually when a piece of code can do it for you?

Simply replace the text for the current year with the code below. You can choose PHP or JavaScript. Note, PHP will get the current year from the server, while JavaScript will get the current year from the local device. Obviously we hope both are in agreement. 🙂 But, the slightly higher possibility of an enduser computer having the wrong year is why I chose to use the PHP method on my websites.

Photo by txmx 2 via Flickr

Photo by txmx 2 via Flickr

PHP

<?php echo date("Y"); ?>

JavaScript

<script>
document.write(new Date().getFullYear());
</script>

Happy New Year!

Please share your thoughts