> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Showing the current year in WordPress posts

> Learn how to automatically show the current year in WordPress posts by adding a brief code snippet to the functions.php file of your theme.

This article describes how to show the current year in [WordPress](https://hosting.com/hosting/platforms/wordpress-hosting) posts. By automatically generating the current year using a shortcode, you can ensure that your posts are always up-to-date.

## Showing the current year

To show the current year in WordPress posts, follow these steps:

1. Log in to WordPress as the administrator.

2. On the Dashboard in the left sidebar, click **Appearance**, and then click **Theme Editor**:\
   ![WordPress - Dashboard - Appearance - Theme Editor](https://static.hosting.com/kb/kb-wordpress-dashboard-appearance-theme-editor.png)

3. In the right sidebar, under **Theme Files**, click **Theme Functions (functions.php)**.

4. Copy the following code snippet and then paste it at the bottom of the *functions.php* file:

```javascript theme={null}
function current_year() {
    $year = date('Y');
    return $year;
}

add_shortcode('year', 'current_year');
```

5. Click **Update File**. WordPress saves the changes to the *functions.php* file.

6. The current year functionality is now enabled, but you must update the post or posts where you want it to appear. To do this, open a post or page on the site, and then type `[year]` where you want to display the current year. For example:\
   ![WordPress - Current year example - Editing](https://static.hosting.com/kb/kb-wordpress-current-year-example.png)

Save your changes, and then view the post:\
![WordPress - Current year example - Post](https://static.hosting.com/kb/kb-wordpress-current-year-example-2.png)

## Related articles

* [Creating custom shortcodes in WordPress](/docs/creating-custom-shortcodes-in-wordpress)

* [Customizing the number of search results displayed in WordPress](/docs/customizing-the-number-of-search-results-displayed-in-wordpress)

* [Displaying the user count in WordPress](/docs/displaying-the-user-count-in-wordpress)

* [Adding a custom logo to WordPress](/docs/adding-a-custom-logo-to-wordpress)

* [Installing WordPress themes](/docs/installing-wordpress-themes)
