How to always show the current year in the copyright on a WordPress website

Having the copyright year update automatically on your WordPress website is a great feature because it will stop your website from looking like its old and outdated.

In WordPress, add this snippet from CSS-Tricks to your functions.php file:

function year_shortcode() {
  $year = date('Y');
  return $year;
}
add_shortcode('year', 'year_shortcode');

Not sure where functions.php can be found? Go to Appearance -> Theme Editor and you should be able to find functions.php in the side menu. Paste the code at the very bottom of the file starting on a new line.

Now, wherever you want to display the date on your site, you can use this shortcode:

[year]

If you want to use it in a template file, you can add this PHP snippet:

<?php echo do_shortcode('year'); ?>

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *