Auto update copyright year on your web page

  • mail-icon
  • phone-icon(+385) 99 8368 558

Updating the copyright year on your website may not be a legal requirement, but it can be small marketing trick. It tells the visitor the site is current, although perhaps you have not updated your content for months.

You can automatically refresh the copyright year by inserting a simple JavaScript or PHP script (see below) into your website's HTML code.

Entering either script won't change the year in the Design view of your html editor. To see the results of entering your script, upload the edited web page to your web server, then go to your browser and reload the page.

Copy and paste scripts wherever you want the current year to appear.

JavaScript:
<script type="text/javascript">
var today = new Date()
var year = today.getFullYear()
document.write(year)
</script>

Result:

PHP script:
<?php echo date("Y"); ?>

Result:

2018

Yes, the php script is simpler, but it may not work just yet. You first need to take another step to make the php script run on html pages.

You need to create or edit an .htaccess file.

This is not as burdensome as it sounds. It's actually a good thing, because then you'll be able to run other php scripts on your site, which can be extremely useful.

Creating the .htaccess File

To set up an .htaccess file, open a new file in a text editor like Notepad and aste the following code:

AddType application/x-httpd-php .htm .html

If you have an existing .htaccess file, open it and add the above code.

If you encounter an error search your web host's site for "How to parse php within html files." Follow its instructions on what code to enter in the .htaccess file. (Your web host might specify a different process for parsing php in html pages. Follow those directions instead of the ones here.)

After inserting the code, in Notepad click File > Save As ...

Type .htaccess as the file name and from the Save as type dropdown menu, selectAll files.

Click Save, then go back and make sure the editor didn't add an extension to the filename after .htaccess. If you find an extension, delete it.

Upload the .htaccess file to the root directory of your website. This is the topmost folder of your website's file structure and is usually named www or public_html or home.

The .htaccess file now affects every other file in your website.

Start and current year in the footer

A range of years next to your copyright symbol subtly reminds the visitor how long you've been in business or how long your website has been up. Use the script to update the last year of your range.

Copy and paste the following as your copyright notice's html code. Change 2002 to the year in which your site was established:

Copyright &copy; 2002 &ndash;

Then enter the JavaScript or php script for the current year immediately next to the semicolon..

Copyright &copy; 2002&ndash;<?php echo date("Y"); ?>

Result:

Copyright © 2002 – 2018

Your copyright year updates are now on autopilot. One less thing to worry about at 00:00:01 next Jan. 1.

This is just one of the details we consider when we design websites. If you need a site designed or redesigned, contact us.

responsive web sites

Responsive web sites

Responsive web sites

Responsive Web Sites is adaptive to a wide range of devices (from desktop computer monitors to mobile phones).

Web site prices

Here you can find prices of our packages. For more detailed information, please contact us.

cloud hosting

Hosting

Hosting

Web hosting or a web space - a place for your website.