Family Encyclopedia >> Electronics

How to Add a Dynamic Copyright Date to Your WordPress Footer

As experienced WordPress developers, we've noticed how outdated copyright dates in footers can undermine a site's credibility. Static years look unprofessional, while just showing the current year hides your site's history. Fortunately, there's a straightforward PHP solution, and an even better WordPress-specific approach using your post data for accuracy.

Basic PHP Approach for Dynamic Copyright

A simple static range like

© 2009 - YourSite.com
requires manual updates as your site ages, which is tedious and error-prone.

Elegant WordPress Solution Using Database Queries

Discovered via @frumph from the ComicPress theme team, this function dynamically pulls the publication years of your oldest and newest posts. New sites show just the current year; established ones display a range like 2009-2023.

Add this to your theme's functions.php file:

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;
}

Then, in your theme's footer.php, insert:

<?php echo comicpress_copyright(); ?>

This outputs something like: © 2009-2016 (adjusted to your content).

Implement this proven technique today to keep your WordPress site's footer fresh and authoritative across all your projects.