Forked from CapWebSolutions/gist:71470cf053a2f1cb37534d49793d4426
Created
August 3, 2021 20:15
-
-
Save Mediatros/a166052792c42611a5fd9a9ecb20f2a2 to your computer and use it in GitHub Desktop.
Create copyright shortcode for use in footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Usage | |
* Use [year] in your posts. | |
*/ | |
function year_shortcode() { | |
$year = date('Y'); | |
return $year; | |
} | |
add_shortcode('year', 'year_shortcode'); | |
/* Current year only. */ | |
© <?php echo date("Y"); ?> | |
/* With start year */ | |
© 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