It's the start of a new year, and if you're anything like me, you're scrambling to check off all those tasks you conveniently ignored in December.
But one task you shouldn't have to worry about? Updating the year in your website's footer.
Too often, developers hardcode years directly into their code. It’s easier at the time but it makes your website harder to maintain by yourselves and requires you to have to follow up every January (while you promise to fix the problem before next year)
Instead, let computers do what they're good at: knowing what year it is.
Here are a few quick ways to make your footer update automatically, depending on your platform:
Squarespace
In a Code Block, add:
<script>document.write(new Date().getFullYear());</script> This is vanilla javascript and will work for any website where all you can do is update some HTML and javascript.
WordPress
In your theme's `footer.php`:
© <?php echo date("Y"); ?> Your Company Name Django
In your template:
© {% now "Y" %} Your Company Name Ruby on Rails
In your view:
© <%= Time.current.year %> Your Company Name If all of this feels too technical, or too daunting (like committing to 75 Hard starting on January 1st) Carbon is here to help. Let's make sure you start the year off right, and *in* the right year.