Skip to content

Instantly share code, notes, and snippets.

@PiotrKrzyzek
Created March 12, 2019 19:33
Show Gist options
  • Save PiotrKrzyzek/078d7778a204859756ec366dfac817c6 to your computer and use it in GitHub Desktop.
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.
/**
* 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