Source: WPBeginner
// The easy way
$blogname = get_bloginfo();
echo '<div>© ' . date( 'Y' ) . ' $blogname</div>';
/**
* The DYNAMIC WAY
*/
function dynamic_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results( "SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status = 'publish' " );
$output = '';
$blog_name = get_bloginfo();
if ( $copyright_dates ) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if ( $copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate ) {
$copyright .= " – " . $copyright_dates[0]->lastdate;
}
$output = $copyright . " " . $blog_name;
}
return $output;
}