How to Automatically Update the Copyright Year: 3 Simple Methods

Every year, when the new year comes around and January arrives, do you find yourself having to manually update the copyright year in the footer?

It’s not a problem if you only have one or two sites, but the more sites you manage (e.g., if you are contracted to create and manage websites) the more work and hassle it becomes to update the year.

Above all, since you’re probably working at the beginning of the year when your brain isn’t working yet, it’s easy to make mistakes, so it’s best to have these things updated automatically.

However, when it comes to automatic updates, there are actually three main ways to do this, and the method you can use will vary depending on how the site is designed, so let’s take a look at each one.

1. Automatic updates using PHP

Many websites today are made with WordPress, which uses PHP, so by entering the following syntax, the year will be updated automatically.

<?php  echo date("Y"); ?>

Just write this wherever you want it to appear, and the year will automatically change when the year changes.

Server’s time settings

Since PHP works on the server side, if you write this code, the year will be dependent on the server’s time settings.

However, on a normal server, unless there are some special cases, it will be no different from the current time, so it works without any problems in most cases, and I actually use this method to write the year in the footer of sites I create using WordPress.

How to include the start year – current year

For example, if you have a website that has been operating for a long time, you may want to include the start year in the copyright. In that case, if you incorporate it together, it will work without any problems.

2010-<?php  echo date("Y"); ?>

If you actually use it, this is the best WordPress copyright year automatic feature available.

© <?php  echo date("Y"); ?> <?php  bloginfo('name') ?> All Rights Reserved.

For example, the copyright mark + year + site name + All Rights Reserved is probably a common usage.

2. How to automatically update using JavaScript

If your site is not PHP, you can also use JavaScript to automatically update it.

<script>
  document.write(new Date().getFullYear());
</script>

By writing it like this, it will be automatically updated just like with PHP.

Strictly client-side

Unlike PHP, JavaScript works on the client side and is therefore subject to the user’s time settings.

However, I don’t think there are many people who set the time to a special time in this way, so it usually works without any problems.

This is a client-side feature and is not visible in the source code.

Because JavaScript works on the client side, when you view it in a browser, the year will be displayed, but if you view the exact source code, the JavaScript syntax will be displayed as is.

Those with experience in SEO may be inclined to dislike the idea of ​​the source not displaying correctly, but the copyright wording should not have any impact, so it’s something to be aware of.

In cases where pages are not created with PHP, such as pages created with static HTML files or landing pages, this JavaScript syntax is often used.

3. How to automatically update using SSI

Surprisingly, many people are not familiar with SSI, but SSI, which stands for Server Side Include, is a surprisingly useful function that allows you to convert HTML files into external files and call them commonly, or display the last update date of a file.

By using this SSI function, you enable a seamless copyright year auto update HTML implementation.

Preparation for using SSI

SSI is a little special, and there are a number of prerequisites to meet.

Does the server allow it?

It is necessary that the server is set up to use SSI. If SSI cannot be used here, it will not be possible to use it in the first place, so please check.

However, most general server companies these days state that SSI can be used in the same way as PHP, so I think it will be usable unless there are extraordinary circumstances.

Write it in .htaccess so that it can be used in HTML files

Strictly speaking, SSI is used with the extension “.shtml”.
Therefore, when using SSI, it is necessary to use .shtml, but in today’s world, there are almost no sites that are composed of shtml.

Therefore, in order to use SSI in HTML, the following statement is required in .htaccess.

Options +Includes
AddHandler server-parsed html

To put it simply,
the first line Options +Includesis what enables SSI so that it can be used, and the second line AddHandler server-parsed htmlis what allows SSI to be used in HTML files as well.

How to write automatic updates using SSI

<!--#config timefmt="%Y" -->
<!--#echo var="DATE_LOCAL" -->

This will ensure it is updated automatically.

SSI is displayed after execution in the source code.

With JavaScript, the year will appear to change in the browser, but when viewed in source code, the script syntax will be displayed as is. However, with SSI, the year after execution will be displayed in the source as well.

Even if it is displayed as “2018” when viewed from the outside, if it is JavaScript, you can see that it is an automatic update by looking at the source. However, with SSI, the same “2018” is displayed even when looking at the source, so at a glance it is not clear whether it is manual or automatic.

SSI can also handle other things like the last update date and the calling of external files, making it extremely easy to use.

It can also handle static files such as HTML.

In addition, using SSI, you can support static HTML files in the same way as JavaScript.

This kind of automation is not possible with HTML alone, but by making good use of SSI, it is possible to streamline processes that would otherwise have to be done manually.

Also, the results of execution are displayed on the source code, so there is also the benefit that you won’t have to worry about anything from SEO experts who are particular about the details.

You may be able to see the differences more easily by looking at the source code and checking whether it is being executed.

Summary

I have summarized how to automatically update copyright. PHP, JavaScript, and SSI each have their own advantages and disadvantages, so let’s go through each of them and decide which one is best to use on your site.

This is purely my personal opinion, but if you are using PHP such as WordPress, use PHP as is, if the site is made up of static files, use SSI, and if you cannot use SSI, use JavaScript.