PHP snippet · Content & Text
Dynamic copyright year shortcode
A shortcode that prints the current year in the site's timezone, plus an optional start year that turns it into a range. Set the footer once.
About this php snippet
The footer year that never goes stale, and never needs a reminder in January when somebody notices the site still says last year.
Usage
- [emcp_year] prints the current year
- [emcp_year start="2019"] prints a range from that year to this one
- [emcp_year start="2019" separator=" to "] changes what sits between the two years
What it does
- Prints the current year, or a range when a start year is given
- Takes a separator attribute, so you can use a dash, an en dash, or a word
- Drops straight into a footer widget, a template, or a page builder text element
Good to know
- The year comes from the WordPress time function, so it follows the site timezone rather than the server's. On a site whose audience is a day ahead of its host, that is the difference between the footer rolling over on time and rolling over several hours late.
- When the start year matches the current year the range collapses to a single year, so a site launched this year does not read as a range of one
- A start year in the future is ignored rather than printed backwards
- Output is escaped, so it is safe anywhere. Works in Elementor, Gutenberg, widgets, and classic templates.



