Hack: Adding a Copyright Message That Automatically Updates

A normal thing to have at the bottom of your WordPress site is a copyright message. This is usually something like “Copyright Mark Davidson 2016-2018.” It kind of covers you from the year you started the site, to the current year.

But then what happens when the new year comes? You’ve got to remember to change the second year to add one. No problem, and easy to do, as long as you remember.

But a better way is to have that year change for you automatically. You can do that with a little PHP.

In WordPress, go to Appearance, Editor. Then choose Theme Footer. The contents of this PHP theme script will appear at the bottom of every page of your site. You can insert the copyright message anywhere, and you may need to experiment to get it in the right place for your particular theme.

For the default Twenty Seventeen theme, a good place is right after the get_template_part line, after the closing ?> on the next line. Here is the code:

Copyright Your Name 2016-<?php echo(date('Y')); ?>

All that the PHP code does is to echo the date function, given the parameter ‘Y’ which will return the year in 4-digit format.

Another good place for it is to replace theĀ get_template_part line. This will remove the Powered by WordPress text and replace it with the copyright message. But since that line is already between <?php and ?> you will need a PHP-only version, like this:

echo('Copyright Your Name 2016-'.date('Y'));

You can also add this code to other parts of the template, such as the sidebar or even the header. It works anywhere there is PHP code.

One downside to this simple code is that it shows one year to another year. So if you just started your site, it may show something like 2018-2018. I’ve seen code that takes that into account, which is nice because you can insert the code and then leave it alone. But then you’ve got a few extra lines of code left there that aren’t really needed after the first year. I’d rather keep it simple and then remember to change it on the first January 1st of your site, and then never again. So during the first year it just shows the current year, like 2018. Then after the first year, it shows the first year the site existed, followed by the current year, like 2018-2019. You just need to remember to make that change one time.

Leave a Reply

Your email address will not be published. Required fields are marked *