Dynamic Copyright Years Shortcode
Registers a [copyright_years] shortcode that outputs a range like "© 2016–2026 Site Name", starting from your first post or a year you choose.
Opens WPIDE on
Code
add_shortcode( 'copyright_years', function ( $atts ) {
$atts = shortcode_atts( array( 'start' => '' ), $atts, 'copyright_years' );
$current = (int) wp_date( 'Y' );
$start = (int) $atts['start'];
if ( ! $start ) {
$first = get_posts( array(
'numberposts' => 1,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'ASC',
'fields' => 'ids',
) );
$start = $first ? (int) get_the_date( 'Y', $first[0] ) : $current;
}
$years = $start < $current ? $start . '–' . $current : (string) $current;
return '© ' . $years . ' ' . esc_html( get_bloginfo( 'name' ) );
} );
Notes
Usage: [copyright_years] or [copyright_years start="2015"].
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.