What is this “better” way?
Most sites running PHP will slap a quick
Copyright © <?php echo date('Y'); ?> Acme Co. in their footer and call it a day. But a lot of visitors have become savvy to that and know that its a trick being played by a computer. You may ask why the copyright year even matters. Well, it may be surprising to find out that many visitors judge your trustworthiness by the age of your website. By slapping the current year in the copyright portion of the site footer you’re telling visitors that you’re either a brand new site or are just putting that there for the sake of putting it there.
Do you even know why you’re putting that copyright statement on your site? It seems like a lot of website owners just do it because they’ve seen if before. If you’re going to use any of these techniques for your own site, please try to have a reason for adding a copyright statement in your footer. Don’t just do it because you’ve seen it before. For me, my reasons are as follows:
- Show visitors how long the site has been running – regardless of how many times I redesign a site, I’ll always use the original publishing year in my copyright notice.
- Establish who owns the content of the website – Technically, you don’t need to put a copyright notice on your website to be granted a copyright. The act of creating and publishing it grants you a copyright automatically (since 1989). That said, by providing the copyright statement on your website you are explicitly letting the world know who is the creator of that work and when the work was originally published. Copyright grants you the right to set the rules for how your content is consumed. Even free and open source works can – and technically are – copyrighted by their creators. If you create an open source project the copyright allows you to say “hey, I made this and I’m giving it away under the MIT or GPL or whatever license but I reserve the right to stop doing that at any point”. I use the copyright statement to take ownership of my work. I want people to know who the person who created it was.
Fun fact: Although you are automatically granted a copyright whenever publishing an original work online, it is hard (maybe impossible) to sue for infringement of that work unless you formally register it with the US Copyright cartel (not their actual name). The problem with digital works like websites though is that even with a formally registered copyright, if you change the website the copyright only covers the version of it that you had originally registered. There’s a great Sitepoint article about website copyrights that explains this in depth.
How it works/What will users see?
Whether you run a static or dynamic site, this method of displaying the copyright will show the correct span of years the site has been operating. It’ll even cover the case where the site is brand new and you only need to display the current year.
For example, if you launched the site in 2005 then this code will show “Copyright 2005 – 2015 Acme Co.”. If your site is brand new and you want to make sure that the copyright not only stays up to date but shows just the current year but not need to update the site later on, then this method will also work. For example, if you publish a site on December 31st, 2014 then for the rest of that day your notice will display “Copyright 2014 Acme Co.” but as soon as the clock strikes midnight on January 1st, your site will automatically display “Copyright 2014 – 2015 Acme Co.”.
Method 1: PHP
You can add this code to your framework as a helper function or hard code it into your template. How you do this really depends on your project and there is no right way, only the way that’s right for you.
1 2 3 4 5 6 7 8 9 10
The code above sets up your initial publication year and will check if the current year is greater than it. If it is then the copyright notice becomes a range. If it isn’t then you only get a single year. The
$copyright = ... statement is a ternary statement. You probably already knew that but if not, a ternary statement lets you do simple if/else comparisons in one line. They exist in just about every language and usually use the same syntax. That line is the same as writing this:
1 2 3 4 5 6 7 8
Why write 6 lines of code when one will do?
If you have a static site with no server side rendering then this method will work the same way except on the client. We do use jQuery here but you can just as easily use vanilla JS.
1 2 3 4 5 6 7 8 9
What we’ve done here is the same as the PHP script with a twist. We store the original copyright year and the current year in variables then we check to see if the current year is greater than the original start year. Here’s the twist: we don’t use an
else or ternary statement in this code. Instead, if the condition is true we replace the text of the
#copyright span with our date range. If it’s false then we keep the text that’s already in there.