If you’ve ever built your own WordPress website, you’ve probably wondered how you can keep your footer copyright year up-to-date automatically. Due to the fact that WordPress themes are not always built following the same standards/styles, I am going to show you 3 different ways you can achieve this.

 

 

Method 1: PHP date(‘Y’) in a child theme file

Depending on how your theme is set up and whether or not you are using a child theme (hint: you should use a child theme – learn how to create a child theme here) you may be able to insert a simple line of PHP code into your child theme to keep your copyright text up-to-date. If that is the case, insert the following code into the appropriate theme file (remove the PHP tags and/or echo as needed):

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

 

Method 2: PHP date(‘Y’) in a shortcode

A lot of premium themes have a copyright text field in either the theme options or the Customizer. Some themes let you insert WordPress shortcodes while others only let you enter HTML. If your theme only allows HTML in the copyright text field you can skip to Method 3 below. If your theme allows you to enter shortcodes, you can add the following code to your child theme’s functions.php file:

add_shortcode('my_copyright_year', 'shortcode_my_copyright_year');
function shortcode_my_copyright_year() {
    return date('Y');
}

You can then add the following shortcode in place of the static year text in your theme’s field:

[my_copyright_year]

 

Method 3: HTML + Javascript

In this method there are two parts. First, add an HTML tag (with an id that you can reference with Javascript) to the theme copyright text field (as discussed in Method 2). This is the tag and id we will use for this tutorial:

<span id="my-copyright-year"></span>

Next, add the Javascript code responsible for adding the current year to the html tag. You may be able to add the code directly to the theme field after the copyright text. If not, you may need to enter it into a custom JS field in your theme or via a WordPress hook in your child theme. It all depends on how the theme is set up. Also, you may or may not need the opening and closing <script> tags. In any case, the Javascript code you need to add is this:

<script>document.getElementById('my-copyright-year').innerHTML = new Date().getFullYear();</script>

 

Conclusion

WordPress themes are diverse and can be configured in many different ways depending on the developer’s personal preferences (some even disregard best practices unfortunately). That being said, I hope you were able to make your copyright year dynamic with one of the above methods. If you ran into issues or would like help making yours dynamic please reach out to me via the Request A Free Estimate form. I’d be happy to give you a hand.


Dustin Parker

Dustin is a web developer with a passion for building custom websites and web applications on platforms/frameworks such as WordPress, Shopify and Laravel.