How to Display the Current Year on Your WordPress Website

Keeping your website up-to-date is crucial for maintaining a professional appearance. One simple way to do this is by displaying the current year dynamically, particularly in your footer or other areas of your site. Instead of manually updating the year every January, you can use a few simple techniques to ensure it updates automatically.

In this post, we’ll explore different ways to display the current year on a WordPress website.

Using PHP to Display the Current Year#

WordPress allows you to use PHP to insert dynamic content. The easiest way to display the current year is by using the PHP date() function. Follow these steps:

Steps:#

  1. Access Your Theme Files:
    • Go to your WordPress admin dashboard.
    • Navigate to Appearance > Theme File Editor.
    • Open the file where you want to display the year (commonly footer.php).
  2. Insert the PHP Code: Add the following code where you want the year to appear:
PHP
<?php echo date('Y'); ?>

This will output the current year, such as 2025.

Example:

If you want the year in your footer copyright, you can use:

PHP
<p>© <?php echo date('Y'); ?> Your Website Name. All rights reserved.</p>

Using a WordPress Shortcode#

If you don’t want to edit your theme files directly, you can create a shortcode to display the year.

Steps:#

  1. Add the Shortcode:
    • Open your theme's functions.php file.
    • Add the following code:
PHP
function display_current_year() {
    return date('Y');
}
add_shortcode('current_year', 'display_current_year');

Use the Shortcode:#

  • Add [current_year] anywhere in your posts, pages, or widgets, and it will display the current year.

Using a Plugin#

If you prefer not to deal with code, you can use a plugin to achieve this.

  • Insert PHP Code Snippet: Allows you to add custom PHP code and use it as a shortcode.
  • Custom HTML Widgets: Some plugins allow dynamic content in widgets.

Install one of these plugins, and you can use the shortcode method without touching your theme files.

Adding the Year in Gutenberg Block Editor#

If you’re using the Gutenberg editor, you can display the year dynamically with the help of plugins like "Insert Blocks". Alternatively, use a custom HTML block to insert the PHP code if your theme supports it.

Testing the Changes#

Once you’ve added the year to your website, make sure it displays correctly:

  • Clear Your Cache: Sometimes, changes might not appear immediately due to caching.
  • Test Responsiveness: Check how the year displays on both desktop and mobile devices.

Displaying the current year on your WordPress website not only saves you time but also ensures your site stays current and professional. Whether you use PHP, a shortcode, or a plugin, the process is straightforward and easy to implement.

By following these methods, your site will always display the correct year, keeping it up-to-date for your visitors.

Not the solution you are looking for?

Please check other articles or open a support ticket.