Poiesis Web Development » Blog Archive » Automatically Changing the Copyright Year in Your Footer

PHPMost WordPress themes have a copyright notice in the footer like the one we use: © Copyright 2003-2009 Poiesis Web Development. The copyright notice is fine for the first year, however, it needs to be updated every January, or your blog begins to look old and unprofessional. Maybe you’re growing weary of having to open the footer.php file to manually change the copyright year every January. Well, since WordPress is based on PHP, there’s a simple solution called the PHP date() function.

The date() function

The PHP date() function returns the current timestamp as a string that can be formatted to displayed particular elements of the timestamp, such as the day, the time, the year, etc. In this post we’re interested in the year and there are two PHP format for year: 'Y', which represents the full year, as in 2009, and 'y', which represents the last two digits of the year, as in 09. The format that we use in the four digit format ('Y').


Implementing the date() function

The copyright notice is in the footer.php file of your theme, so you’ll need to open that in a text editor, such as Notepad. Locate the copyright notice and replace it with the following code:

&copy; Copyright 2006-<?php echo date('Y'); ?> <a href="<?php bloginfo('siteurl'); ?>"><?php bloginfo('name'); ?></a>

Just change 2006 to the year that you started your blog.

Tags: ,


Leave a reply