Code Bytes
Update a footer year without document.write
Keep a footer year current using a small JavaScript enhancement or a server-rendered PHP date, with a readable fallback.
A small footer job
If you display the current year in your footer, generate it in the template or build when possible. A browser enhancement is also fine, provided the footer remains readable without it. There is no need for document.write().
Browser version
<p>Example Studio © <span data-current-year>2026</span></p>
const year = String(new Date().getUTCFullYear());
for (const element of document.querySelectorAll('[data-current-year]')) {
element.textContent = year;
}
Put the JavaScript in your existing deferred script. Change the business name and fallback year in your template. UTC makes the rollover consistent across visitors; use your chosen business timezone in the server version if that is more appropriate.
PHP version
<p>Example Studio © <?php
echo (new DateTimeImmutable('now', new DateTimeZone('Europe/London')))
->format('Y');
?></p>
Save that in a PHP template served by PHP, not in a normal HTML file or an editor field that strips executable code. In a static build, compute the year during the build and rebuild when it changes.
Things to keep in mind
The browser version uses the visitor's clock. A cached PHP page or an old static build can keep showing the previous year until refreshed. If you prefer a range such as 2011–2026, keep the genuine starting year fixed and update only the ending year.
This is a display helper, not a way to establish when content was created or who owns it. Keep article publication dates separate.
References: why to avoid document.write, UTC year, and PHP date formatting.
Original version19 May 2016
Kept here for reference and earlier links. The updated guide above is the recommended starting point; older code may depend on retired services or different software versions.
One of the most basic dynamic text areas on a website is the ubiquitous copyright year in a footer of a website.
Generally people use a basic PHP Date echo to output the current year:
PHP:
<?= date('Y'); ?>
However, with Wordpress, it's a bit harder to use PHP within certain themes, widgets and other kinds of builders as it often gets mutated or formatted as PHP can be potentially dangerous to write directly inside of Wordpress.
This below code though is a very simple JavaScript snippet that will print the current year and will work with all text editors such as widgets and theme editors in Wordpress etc.
JavaScript:
<script>document.write(new Date().getFullYear());</script>Keep exploring