HomeWeb application programmingPHP programmingPHP: Print the current year for copyright notices

PHP: Print the current year for copyright notices

Hardcoding the year in a copyright notice is an easy way to get a blog or other website started, just placing the starting and ending years next to the copyright symbol. We have the very best of intentions to change this number right after the big ball drops in Times Square each year. We’re also human and, all too often, I see websites with copyright notices that are years behind. If your website is PHP-powered, this quick bit of code will put the current year in your copyright notice and off of your mind.


To change your copyright notice, or anything else you’d like that should display the current year, you must first find the script in which the copyright display is generated. If you are using a WordPress blog, for example, this is likely in your footer.php file in the directory of the theme you are using. If you aren’t sure which file holds this, you could try searching for the text © in all of the scripts that make up your website. This is the code that generates the copyright logo and should lead you directly to the file(s) involved.

Once you’ve found this, there are two possibilities for including the year information depending on how the script is setup. It is possible that the script is sending the line including the copyright information from an ‘echo’ command in PHP, something like:

echo '© 1812–2006 Olde Time Blogs';

In this case you need to modify this PHP echo command so that it calls the PHP date command. Note that the command could also work with double quotes instead of single quotes, just be sure to keep using the same kind.

echo '© 1812–'.echo date('Y').' Olde Time Blogs';

In PHP, the period symbol is used to stitch together strings, so the command above makes one string out of three.

The other possibility is that the PHP script is formatted as HTML content with separate PHP instructions enclosed by opening/closing PHP tags. This is more proper and common in applications like WordPress. In this case, inserting a dynamic, ever-correct year is a matter of changing:

© 1812–2006 Olde Time Blogs

to

© 1812– Olde Time Blogs

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!