Skip to content

Instantly share code, notes, and snippets.

@dsmy
Created November 16, 2015 16:03
Show Gist options
  • Save dsmy/ed57c5e8ee3b5dd5a80c to your computer and use it in GitHub Desktop.
Save dsmy/ed57c5e8ee3b5dd5a80c to your computer and use it in GitHub Desktop.
Auto update copyright in footer with error protection
<!--Referenced from https://css-tricks.com/snippets/php/automatic-copyright-year/-->
<!--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('2009'); // 2009 - 2015 ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment