Add an auto-updating Copyright to your website with Javascript

Websites need to have the copyrights on them. Usually this is found in the footer of the site. As I was updating a client’s site the other day I noticed his copyright info was still 2009; so I updated it in the template, applied it to the pages, and re-uploaded everything to the live site.
One of the worst things you can do with your website is to not make updates once it’s live. Fresh content is the only thing that will keep your users AND search engines returning. One of the best ways to let users know that you never update your website (saaarcasm), is to have a copyright in the footer of your website from 2003. It really is a pain to have to go in at the first of every year to update all of your client’s websites though. Luckily, Javascript can save us. Using Javascript we can add a copyright to the webpage that will automatically update with the current year. Check out the demo, and then keep reading to grab the code.
All you need to do is paste the following code right into the XHTML where you want the copyright to show up, Javascript does the rest!
<script type=”text/javascript”>
var currentTime = new Date()
var year = currentTime.getFullYear()
document.write(year)
</script>
</p>


June 2nd, 2010 at 6:42 am
Isn’t is easier to use PHP’s echo date(‘Y’)? You save yourself 5 lines of code.
June 8th, 2010 at 3:20 pm
I suppose, as long as you know the server is going to run PHP. I use the above code on every site, so I don’t worry if they have PHP.