Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CapWebSolutions/71470cf053a2f1cb37534d49793d4426 to your computer and use it in GitHub Desktop.
Save CapWebSolutions/71470cf053a2f1cb37534d49793d4426 to your computer and use it in GitHub Desktop.
Create copyright shortcode for use in footer
/*
* Usage
* Use [year] in your posts.
*/
function year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'year_shortcode');
/* Current year only. */
&copy; <?php echo date("Y"); ?>
/* With start year */
&copy; 2008-<?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(); // 2011?>
<?php auto_copyright("2010"); // 2010 - 2017 ?>
/*
* Thanks to:
* ref: https://css-tricks.com/snippets/php/automatic-copyright-year/
* https://css-tricks.com/snippets/wordpress/year-shortcode/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment