How To Automatically Update Dynamic Year In WordPress Post Titles

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!

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: August
add_shortcode( ‘month’ , ‘current_month’ );
function current_month() {
$month = date(“F”);
return “$month”;
}
//* Shortcode to display the current year in WordPress
//* shortcode: 2024
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 August or 2024 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: August
add_shortcode( ‘month’ , ‘current_month’ );
function current_month() {
$month = date(“F”);
return “$month”;
}
//* Shortcode to display the current year in WordPress
//* shortcode: 2024
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 August or 2024 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.

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.

  • Evely Navery says:

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

  • GaryP says:

    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!

    • David Sandy says:

      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.

      • JL says:

        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: 2024
        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 2024“. However, on the front end, it was shown as “The Best XXXXX in 2024” 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?

        • David Sandy says:

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

  • Adi says:

    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

  • David Sandy Ebook Trilogy Books

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

    >
    0 Shares
    Share
    Tweet
    Pin