Skip to content

Showing the current year in WordPress posts

Sometimes you may want to automatically display the current year in your WordPress posts or pages—for example, in a copyright notice or footer. Instead of manually updating it every year, you can use a shortcode to keep it dynamic. On ruachost.com, this can be achieved by adding a simple PHP function.

  • Keeps your site up‑to‑date automatically.
  • Saves time by avoiding manual edits each year.
  • Useful for copyright notices, seasonal content, or date references.
  1. Log in to WordPress with an administrator account.

  2. In the dashboard, go to Appearance → Theme Editor.

  3. From the right‑hand column, select the file named functions.php.

  4. Scroll to the bottom of the file and add the following code:

    function current_year_shortcode() {
    $year = date('Y');
    return $year;
    }
    add_shortcode('year', 'current_year_shortcode');
  5. Click Update File to save changes.

  • To display the current year anywhere in a post or page, type:

    [year]

✅ WordPress will automatically replace [year] with the current year (e.g., 2025).

  • Always back up your site before editing theme files.
  • Consider using a child theme to preserve changes during updates.
  • This shortcode works in posts, pages, and even widgets that support shortcodes.