Skip to content

Instantly share code, notes, and snippets.

@jimmitchell
Last active July 30, 2016 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmitchell/3398b70bf12eb0c7b4ca516fd941a3dd to your computer and use it in GitHub Desktop.
Save jimmitchell/3398b70bf12eb0c7b4ca516fd941a3dd to your computer and use it in GitHub Desktop.
<?php
// Gets the year of your first published post, the current year, and displays the year range between them.
// If both are the same year, just displays current year. Change "slug" to your theme's domain.
function slug_copyright() {
$fp_get_all = get_posts( array(
'numberposts' => 1,
'post_status' => 'publish',
'order' => 'ASC'
) );
$first_post = $fp_get_all[0];
$fp_date = $first_post->post_date;
$fp_year = date( "Y", strtotime( $fp_date ) );
$cur_year = date( "Y" );
if ( $cur_year === $fp_year ) {
$copyright = sprintf( "&copy; %s %s", $cur_year, get_bloginfo( 'name' ) );
}
else {
$copyright = sprintf( "&copy; %s &ndash; %s %s", $fp_year, $cur_year, get_bloginfo( 'name' ) );
}
echo $copyright;
}
?>
// Invoke in theme with the following function call in your theme "footer.php" file...
<?php slug_copyright(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment