How to Add a Dynamic Copyright Date in WordPress Footer

—

by

in

Simple PHP Solution for Dynamic Copyright Date

footer.php

© 2009 – <?php echo date('Y'); ?> YourSite.com

Elegant WordPress Solution for Dynamic Copyright Date

function.php

function comicpress_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 = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}

footer.php

<?php echo comicpress_copyright(); ?>

This function will add the following text:

© 2009 – 2016


Comments

Leave a Reply Cancel reply