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.

More php snippets

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.