# Showing the current year in WordPress posts

> Show the current year automatically in WordPress posts and pages with a simple shortcode added to your theme.

Source: https://helpcenter.ruachost.com/wordpress/guides/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.

## Why Use a Dynamic Year?

- Keeps your site up‑to‑date automatically.
- Saves time by avoiding manual edits each year.
- Useful for copyright notices, seasonal content, or date references.

## Steps to Add Current Year Shortcode

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.

## ⚙️ Using the Shortcode

- 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**).

## Important Notes

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