How To Automatically Update Dynamic Year In WordPress Post Titles

This post contains affiliate links. If you buy through one, I may earn a commission at no extra cost to you. I only recommend tools I believe are useful. Read my disclosure.

I’ll be covering in this post how to automatically update the year in WordPress post titles.

Plus, I’ll also share:

  • Why adding a dynamic year to WordPress post titles for your blog posts and pages is important?
  • The steps required to add dynamic year and month to blog post titles.
  • The code ready to copy and paste to use with Rank Math and Yoast SEO.

Ready to get started?

Let’s dive right in!

Quick answer (last checked: November 17, 2026)

If you only need the year or month in the SEO title or meta description, you do not need any code. Rank Math has built-in variables (%currentyear% and %currentmonth%) and Yoast SEO has %%currentyear%% and %%currentmonth%%. The code in this post is for putting the year in the visible post title itself.

Before you paste code: make a full backup, and use a child theme or a code snippets plugin instead of editing your theme’s functions.php directly, because a typo can break your site and a theme update can erase your changes. The date() function in the code uses your server’s timezone.

Why Is It Important To Add Dynamic Year & Month To Automatically Update WordPress Post Title?

If you think about it, people quickly scan results whenever they do a Google search for a certain keyword.

A lot of times we first look at the title of the first few results to see what matches up best with what we were looking for.

More often than not, certain search queries such as for review posts will come up with the year.

Take a look at the example below when searching for “Elementor review“.How To Automatically Update Dynamic Year In WordPress Post Title Example

In this case, you’ll notice that both the month and year are shown in the title.

Using the power of dynamic month and dynamic year, you WordPress post is inherently more likely to have a higher click-through rate (CTR) and viewed as fresher content in the eyes of someone searching.

Now, let’s take a look at the steps required to setup the date to be automatically updated within the title of a post.

How To Automatically Update Dynamic Year In WordPress Post Title For Rank Math & Yoast SEO

Here’s a quick overview of the steps required to add a dynamic year to a blog post title:

  1. Use code to copy and paste into your theme’s functions.php file
  2. Add the month and year shortcode into the WodPress post title and either the Rank Math or Yoast SEO title box depending on which plugin you’re using
  3. Submit post to Google Search Console to quickly test to see if it is showing up properly in the Google search results

Copy & Paste Code For WordPress & Rank Math Into Functions.php

Go to Appearance -> Theme Editor and copy and paste the following code into the bottom of the file.


//* Shortcode to display the current month in WordPress
//* shortcode: [month]
add_shortcode( ‘month’ , ‘current_month’ );
function current_month() {
$month = date(“F”);
return “$month”;
}
//* Shortcode to display the current year in WordPress
//* shortcode: [year]
add_shortcode( ‘year’ , ‘current_year’ );
function current_year() {
$year = date(“Y”);
return “$year”;
}
add_filter( ‘the_title’, ‘do_shortcode’ ); // activate shortcode in WP Title
add_filter( ‘rank_math/frontend/title’, ‘do_shortcode’ ); // activate shortcode in Rank Math Title
add_filter( ‘rank_math/frontend/description’, ‘do_shortcode’ ); //activate shortcode in Rank Math Meta Description


The code above allows you to then use either the [month] or [year] shortcode in place of where the date would normally be in the title or meta description of the post.  This shortcode should be used if you’re using Rank Math.

Copy & Paste Code For WordPress & Yoast SEO Into Functions.php

Go to Appearance -> Theme Editor and copy and paste the following code into the bottom of the file.


//* Shortcode to display the current month in WordPress
//* shortcode: [month]
add_shortcode( ‘month’ , ‘current_month’ );
function current_month() {
$month = date(“F”);
return “$month”;
}
//* Shortcode to display the current year in WordPress
//* shortcode: [year]
add_shortcode( ‘year’ , ‘current_year’ );
function current_year() {
$year = date(“Y”);
return “$year”;
}
add_filter( ‘the_title’, ‘do_shortcode’ ); // activate shortcode in WP Title
add_filter( ‘wpseo_title’, ‘do_shortcode’ ); // activate shortcode in Yoast Title
add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ ); // activate shortcode in Yoast Meta Description


The code above allows you to then use either the [month] or [year] shortcode in place of where the date would normally be in the title or meta description of the post.  This shortcode should be used if you’re using Yoast SEO.

Now go ahead and save the functions.php file, add the shortcode into the WordPress post title and either Rank Math or Yoast SEO title to automatically update the month and year.

How To Automatically Update Copyright Year For WordPress Site

Besides auto updating the date for WordPress post titles, you can also auto update the year dynamically for the copyright year of your WordPress website.

Simply copy and paste the following into your functions.php and you can use the [copyright_year] shortcode to automatically update the copyright year.

Copy & Paste Code To Automatically Update Copyright Year

//* Shortcode to display the Copyright Year in WordPress
//* shortcode: [copyright_year]
add_shortcode( ‘copyright_year’ , ‘add_copyright_year’ );
function add_copyright_year() {
$copyright_year = date(“Y”);
return ‘© ‘ . “$copyright_year”;
}

Conclusion

Hopefully you were able to get everything working now to automatically update the year in your WordPress post title.

I personally use the shortcode in this post and now you can too in order to not have to worry about manually updating the year and month each time.

Let me know in the comments below any questions or issues.

Can I add the current year to my SEO title without code?

Yes. In Rank Math, use the %currentyear% variable in your title or description template. In Yoast SEO, use %%currentyear%%. Both also have a current month variable. This changes the SEO title shown in search results, not the post title shown on your page.

Is it safe to edit functions.php?

It is risky because a small error can take your site down, and theme updates can overwrite your changes. Use a child theme or a code snippets plugin, and keep a backup so you can undo changes.

Suggested Posts For You…

Affiliate Disclaimer

I hope you enjoyed this post. This post may contain affiliate links, meaning I get a commission if you decide to purchase through my links at no additional cost to you.

Picture of David Sandy

David Sandy

David Sandy is a digital marketer and online entrepreneur dedicated to helping others build successful online businesses. Tools I Use: Elementor Pro, Thrive Comments, & Thrive Leads for blog design, ActiveCampaign for email marketing, DropFunnels for sales funnels, & ClickMagick for link tracking. Follow me on Twitter! Follow me on Facebook! Suscribe to my YouTube Channel! “For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life.” John 3:16 “because, if you confess with your mouth that Jesus is Lord and believe in your heart that God raised him from the dead, you will be saved. For with the heart one believes and is justified, and with the mouth one confesses and is saved.” Romans 10:9-10

David Sandy Ebook Trilogy Books

Get All 3 Of My Ebooks... For Free!

  • There is a piece of great information. I use these techniques, and it’s useful for me. Thanks, David, for the great blog. Keep sharing. 🙂

  • I thought Rank Math came with ability to put variables in form month & year. What does this code add to the built in functionality? Thanks!

    • By using the code, you can use the shortcode anywhere in your post or page across your site. The Rank Math variables (%currentyear% and %currentmonth%) only work in the title and meta description from what I understand.

      • I tried the code that you gave for Rank Math, but it still doesn’t work for my blog post titles. :S

        This is the code I added in the functions.php file:
        /* Shortcode to display the current year in WordPress
        //* shortcode: [year]
        add_shortcode( ‘year’ , ‘current_year’ );
        function current_year() {
        $year = date(“Y”);
        return “$year”;
        }
        add_filter( ‘the_title’, ‘do_shortcode’ ); // activate shortcode in WP Title
        add_filter( ‘rank_math/frontend/title’, ‘do_shortcode’ ); // activate shortcode in Rank Math Title
        add_filter( ‘rank_math/frontend/description’, ‘do_shortcode’ ); //activate shortcode in Rank Math Meta Description

        For my blog post title, I wrote “The Best XXXXX in [year]“. However, on the front end, it was shown as “The Best XXXXX in [year]” instead of “The Best XXXXX in 2020”, which is why I’ve changed back the blog post title to “The Best XXXXX” for now.

        Do you have any idea what could have gone wrong?

        • You need to have two slashes in the first line for it to be a comment. Try copying and pasting the code again.

  • I have successfully used it in the meta description, but og: title, og: description, twitter: title and twitter: description still show the shortcode. how to solve this problem. thanks

  • >
    0 Shares
    Share
    Tweet
    Pin