daniel-w
8/23/2016 - 8:16 PM

A function and shortcode to display a copyright statement.

A function and shortcode to display a copyright statement.

/**
* Copyright Year
*/
function auto_copyright($year = 'auto', $attribution = NULL){
	$date = NULL;

	if ($attribution == NULL) {
		$attribution = get_bloginfo('sitename');
	} if(intval($year) == 'auto'){
		$year = date('Y');
	} if(intval($year) == date('Y')){
		$date = intval($year);
	} if(intval($year) < date('Y')){
		$date = intval($year) . ' - ' . date('Y');
	} if(intval($year) > date('Y')){
		$date = date('Y');
	}

	$copyright = "&copy; " . $date . " " . $attribution;
	return $copyright;
}

/**
* Copyright Year Shortcode
* eg. [copyright starting_year="2016" attribution="DMT Industrial Fabrication"]
*/
function copyright_shortcode( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'starting_year' => 'auto',
			'attribution' => NULL,
		),
		$atts,
		'copyright'
	);

	return auto_copyright($year = $atts['starting_year'], $attribution = $atts['attribution']);
}
add_shortcode( 'copyright', __NAMESPACE__ . '\\copyright_shortcode' );