2010 is now one week old. Have you updated the copyright date in your website(s) yet?
When I was updating the copyright date in our website and our clients’ websites this week it occurred to me that there should be a way for the date to be updated automatically, and there is IF your website is dynamic and uses PHP like Joomla or WordPress does.
While implementing these changes I encountered three different ways various Joomla templates (and a WordPress theme) handle the copyright information. There are probably more possibilities, but the basic coding principle is going to apply in each situation, so you may need to put some thought into making this work if your website is set-up differently than one of the three options I’m going to describe.
Also, this tutorial is exactly that, a tutorial. In no way should this information be construed as legal advice in any form. I’d also recommend making a fresh backup of your website (files and database) before making any significant changes. Having said that, here’s how to do it.
Joomla website copyright date
Most, if not all, of the websites I’ve encountered put the copyright at the bottom of each page. For a Joomla website that means it will probably be in the footer or one of the bottom modules. You will need to open your index.php file in a text editor such as Notepad++ and scroll down to the bottom of the file. What you’re looking for is text that is similar to this:
Standard copyright information
© Copyright 2009, [Your Company Name]. All rights reservedNote: When your web browser encounters the combination & copy ; (without the spaces) in the code it renders this symbol instead: ©
That text will probably be inside an HTML div tag and may have a CSS class or id selector of “copyright” or something similar. If it sounds like I’m being vague, it’s because I am – there are different ways to write code and generate websites.
Once you’ve located the copyright text you should insert the following short line of PHP code
Current year as PHP date variable
<?php echo date('Y');?>into the copyright text so that the final result looks like this:
Copyright text with current year as PHP date variable
© 2009-<?php echo date('Y');?>, [Your Company Name]. All rights reservedAssuming the current year is 2010, that code string will generate this output in our website (Black Hills Web Works):
© Copyright 2009-2010, Black Hills Web Works. All rights reserved
This real-world example shows the difference between a static website (old school) and a dynamic website like Joomla or WordPress. In a static website the copyright date needs to be typed and eventually changed on each and every web page that makes up the website. In a dynamic website, that little bit of PHP tells the website to ask the server what the current year is, and then it displays (prints) it out on the visitor’s web browser for every page that visitor visits.
There is a slight catch in this formula: the year that is displayed is the year where the server is located, not necessarily where the visitor is, unless they are in the same time zone. Not a big deal when you’re talking years though, since at most it will only be 23 hours off and probably much less, and more than likely no one will notice.
Also, I’ve set this up to include a date range for copyright such as “2009-2010.” If you want only the current year to be displayed you would simply remove the “2009-” from these code examples.
Three different situations
I mentioned earlier that different templates handle the copyright date differently. Here are the three situations that I’ve encountered:
1. “Static” text in the index.php file
All of our Joomla websites to-date are using RocketTheme templates, and RocketTheme has changed the way they write their code as time progresses, which is to be expected. In the older templates like TerranTribune the copyright text is actually in the index.php file, and you need to open that file and edit it’s contents to change the copyright information, as explained above.
2. Text box in the template manager
In the more recent RocketTheme templates like Nexus or Infuse there is a text box in the template manager that allows you to enter your copyright information without opening and editing the index.php file. The problem with this option is that you can’t enter the PHP code that displays the current year into this text box. (Actually you can, but it doesn’t do anything.)
The index.php file in this situation looks like this:
Copyright text as PHP variable
<div id="copyright" >© <?php echo $copyright_text; ?></div>The PHP in this case is asking for the text that was entered into the copyright text box in the template manager. The solution is to do away with that bit of PHP and insert our own in its place, along with the rest of the copyright text so that it looks like this:
Copyright text with current year as PHP date variable
© Copyright 2009-<?php echo date('Y');?>, [Your Company Name]. All Rights ReservedWith that change, you would still want the template manager “display copyright” option to be “Yes,” but entering anything in the copyright text box will have no effect on the website itself.
3. Copyright information in a module
We have a couple websites that, for whatever reason at the time, we chose to display the copyright information in a custom HTML module instead of in the index.php file. This works fine until you want to add some PHP magic to automatically display the current year in the copyright text. The problem here is that Joomla doesn’t accept or acknowledge PHP code in the content of an HTML module.
Fortunately there is a work-around. A quick Google search for “php in joomla module” turned up a result for a Joomla extension called Joomla Mod PHP. This module allows you to enter PHP into a module position, which is really cool. The text/code I entered into the text box in this module is the text that I had in the custom HTML module along with the PHP code that generates the current year. It looks like this:
HTML and PHP as entered in PHP module
<div style="text-align: center;">© Copyright 2009-<?php echo date('Y');?>, Black Hills Web Works. All Rights Reserved</div>Publish the PHP module to the same module position as the previous copyright module and unpublish that previous module and the only difference when the website is displayed should be the addition of the current year in the copyright text.
What about WordPress?
Admittedly I have more experience with Joomla than I do with WordPress, but this blog is powered by WordPress so I am becoming familiar with how it works.
Since both Joomla and WordPress use PHP to generate webpages, the only difference I found was the location of the copyright information. Where Joomla puts that at the bottom of the index.php file, WordPress uses a footer.php file (in my experience, at least). Open the footer.php file in your favorite text editor, find the copyright information, make the appropriate change based on how it’s coded as explained above, and you’re done.










