Thursday, 9 August 2018

PHP Footer Copyright Year

This is a small tutorial / code snippet on how to display the correct copyright year with PHP. In PHP, you can get the current year like so:
Using PHP’s date function, we can determine what year range we should display in our copyright notice.
Here is the first example:
In the example above, we set 2012 as our “start year”. If you plan on using the code above, you will need to change the $startYear variable to match the year that your website came into existence (or the year that your website started to publish content).
If the $startYear is not the same as the current year, the code will display a date range (Example: 2012-2014). However, if the start year is the same as the current year, then we simply display a single year (Example: 2014).
To make things even simpler, I have created the following copyright function:
As you can see, the first parameter is the name of the website (or your personal name, depending on what you want), whereas the second parameter is the start year. Note that the start year is an optional parameter. If you decide to omit the start year, then you can just provide the name of your website. I’ve also taken the liberty of adding the copyright symbol, as well as the “All Rights Reserved” text.
If you’re not interested in adding functions and you’re wanting to keep it confined to one line of code, you can use the following snippet:
Obviously, you will need to change 2012 to match the start year of your website.

0 comments:

Post a Comment