October 5, 2020

How to add a dynamic year to your website footer.

If you've ever looked at a website and noticed the copyright year in the footer is something "2015" and it's really 2020, then you may even wonder if the site is still active. It could be that the owner forgot to update it, or that they simply don't know how to.

This tutorial will show you several methods to set a dynamic year (auto updates for you). Here's a how to literally "set it, and forget it" so that it automatically updates each year for you.

Even though I'm just posting this tutorial, I've been implementing a dynamic year into all the websites I build for a while now. However since the demand has grown, I've decided now is a good time to share.

Below you'll see five methods, plus one for Oxygen Builder users, to achieve this:

PHP

This snippet serves the information via PHP from the server. Simply place it in your footer. If you're using WordPress, place it in your footer.php file. Here's some video tutorials on this.

// Adds current year
<?php echo date("Y"); ?>

The end result is:
2020 (or whatever is the current year.)

This next one pulls the date of the first published post/page or one you preset as a fallback, and the site title for you. Be sure to change the link and any text you need otherwise you'll just be giving me credit. 🙂

// Adds auto-generated Copyright from Site title/year
<?php 
function create_copyright() {
$all_posts = get_posts( 'post_status=publish&order=ASC' );
$first_post = $all_posts[0];
$first_date = $first_post->post_date_est;
_e ( 'Copyright © ' );
if ( substr( $first_date, 0, 4 ) == date( 'Y' ) ) {
echo date( 'Y' );
} else {
echo substr( $first_date, 0, 4 ) . "2015 - " . date( 'Y' ) ;
}
_e( ' • ');
echo ' <strong>' . get_bloginfo( 'name' ) . '</strong> ';
_e( '| A <b><a href="https://jeffbrigman.com" target="_blank">JeffBrigman.com</a></b> Website.' );
} ?>

The result is:
Copyright © 2015 - 2020 • Jeff Brigman | A JeffBrigman.com Website.

Here's one more version that's in between the two previous ones. Be sure to set the fromYear to whatever year you need and the business/website name.

© <?php
  $fromYear = 2015; 
  $thisYear = (int)date('Y'); 
  echo $fromYear . (($fromYear != $thisYear) ? '-' . $thisYear : '');?> Business Name

The result is:
© 2015 - 2020 • Business Name

Javascript

As a note of warning, the following javascript is dependent on the users browser settings. Normally it will display correctly, but there may be instances where the end user has forced the Date/Time to be different.

© <script type="text/javascript">document.write(new Date().getFullYear());</script>

The end result is:
2020 (or whatever is the current year.)

© 2015<script>new Date().getFullYear()>2015&&document.write("-"+new Date().getFullYear());</script> | Business Name

The end result is:
© 2015 - 2020 | Business Name

Oxygen Builder

This final version, which is for the Oxygen Builder, can also be used for any builder that allows for dynamic PHP data to be used.

Add a regular Text component, then double click and add your text. For example: © 2011 - 2015 | Jeff Brigman

Next highlight the "2015" and click on Insert Data.

Scroll down and click on Advanced: PHP Function Return Value.

Under Function Name, add date (all lower case), and under Function Arguments, add Y (uppercase).

Then click Insert. Since the component is still selected, it will now show the inserted PHP code in place of where the highlighted year originally was.

Simply click onto any other component in the builder page and watch it now update to the current year.

There you have it, six ways to add a dynamic year to your website footer. Thanks for reading and if this helped you, please share.

Have a question?

Get in Touch

+1 (865) 603-6330
Copyright © 2011 - 2020 | Jeff Brigman
enveloperocket linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram