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“.
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:
- Use code to copy and paste into your theme’s functions.php file
- 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
- 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
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
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.
David Sandy
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
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. 🙂
No problem. Thanks! ?
🙂
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: 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?
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