how to automatically update your copyright year

24 March 2020by admin

You can automatically refresh the copyright year by inserting a simple JavaScript or PHP script (see below) into your website’s HTML code. Entering either script won’t change the year in the Design view of your html editor.

Current year only

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

With start year

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

Start date with error protection

<?php function auto_copyright($year = 'auto'){ ?>
   <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
   <?php if(intval($year) == date('Y')){ echo intval($year); } ?>
   <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
   <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
<?php } ?>

Usage:

<?php auto_copyright(); // 2020?>

<?php auto_copyright("2010");  // 2010 - 2020 ?>