Created
March 12, 2019 19:33
-
-
Save PiotrKrzyzek/078d7778a204859756ec366dfac817c6 to your computer and use it in GitHub Desktop.
WordPress shortcode to show the copyright year as well as years in business from given starting date.
This file contains hidden or 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
/** | |
* Shortcode for the yearly display items | |
* | |
* @param [array] $atts The attributes passed to the shortcode | |
* | |
* @return void | |
*/ | |
function showTheYear( $atts ){ | |
$yearStarted = if(isset($atts['yearStarted'])) intval($atts['yearStarted']) : 1999; | |
$yearsInBusiness = if(isset($atts['years']))? true : false; | |
$copyYear = if(isset($atts['copy']))? true : false; | |
$copyText = if(isset($atts['copyText']))? $atts['copyText'] : '© This is our site'; | |
if ($yearsInBusiness) | |
echo date("Y") - $yearStarted; | |
elseif ($copyYear) | |
echo $copyright_year = 'Copyright ' . date("Y") . $copyText; | |
} | |
add_shortcode('years', 'showTheYear'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment