# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: content, shortcode, copyright, footer
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/copyright-years-shortcode/

## Code

```php
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 . '&ndash;' . $current : (string) $current;

    return '&copy; ' . $years . ' ' . esc_html( get_bloginfo( 'name' ) );
} );
```

## Notes

Usage: [copyright_years] or [copyright_years start="2015"].

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Dynamic Copyright Years Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
