Last active
January 22, 2019 17:54
-
-
Save morgyface/e273d4d3470d406dffee40e12105c93c to your computer and use it in GitHub Desktop.
WordPress | Dynamic copyright with current year and site title plus tagline
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
<?php | |
$build_year = '2018'; // Amend this accordingly using the YYYY format | |
$year = date('Y'); // Get A full numeric representation of the current year, 4 digits | |
$blogname = get_bloginfo( 'name' ); // Get the Site Title as specified in Settings / General | |
echo '<p class="copyright">©'; | |
if ( $build_year == $year ) { | |
echo $year; | |
} else { | |
echo $build_year . ' - ' . $year; | |
} | |
echo ' ' . $blogname . '. All Rights Reserved.</p>' . PHP_EOL; | |
?> | |
<?php | |
// As a ternary operator | |
$build_year = '2018'; // Amend this accordingly using the YYYY format | |
$current_year = date('Y'); // Get A full numeric representation of the current year, 4 digits | |
$range = $build_year . '-' . $current_year; | |
?> | |
<p>©<?php echo ( ( $build_year == $current_year ) ? $build_year : $range ) ?> Business Name. All Rights Reserved.</p> | |
<?php | |
// Returns either copyrighted date range or single date | |
function copyright( $build_year ) { | |
// Build year should be in YYYY format | |
$current_year = date('Y'); // Get A full numeric representation of the current year, 4 digits | |
$blogname = get_bloginfo( 'name' ); // Get the Site Title as specified in Settings / General | |
$copyright = '©'; | |
if ( $build_year == $current_year ) { | |
$copyright .= $current_year; | |
} else { | |
$copyright .= $build_year . ' - ' . $current_year; | |
} | |
$copyright .= ' ' . $blogname; | |
return $copyright; | |
} | |
?> |
Updated in early 2018, now available as a function.
Example usage:
<p><?php echo copyright( '2018' ) ?>. All Rights Reserved.</p>
Added a ternary operator version. Useful for templating.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dynamic Copyright
I've updated this to include a copyright year range. So rather than always displaying the current year, it displays the build date to the current year. For example:
If the build year and current year are the same there is no range.