This article is all about Adding a Dynamic Year in Selected Post Titles. I will share why you should Add Current Year in WP Post title using the shortcode. Along with that, I will also explain A Unique way to Auto Add Dynamic Year in WordPress Post Titles.
Using the same method, you can not only add a year, but you can also add month/date and/or day to WordPress Title. So that you can change the WordPress page title dynamically.
But before digging into the details, I would like to ask a very simple question about your behavior on the internet.
Have you ever observed your behavior to click on the Google Search Results Page?
Did you notice any pattern for choosing a particular link or post?
Hmm?? Any Guesses..??? Think about it for a second.
Okay, let me explain why I asked you to think about your behavior.

☲ Table of Contents
- Why you should Add Dynamic Year in WordPress Post Titles
- How you should Add Dynamic Year in WordPress Post Titles
- Wrapping it Up
Why you should Add Dynamic Year in WordPress Post Titles
According to a study, humans’ eyes don’t read all the letters one by one, especially on the internet. Human eyes scan text for Highlighted Words, Numbers and Bullet Points.
Out of these three; Numbers made the most impact on the human brain. Digits or figures easily slides into your mind and hit it hard. After that, our mind says ‘this message is important’. And this is how we choose to discover the same.
Now, let’s assume that you have searched ‘fastest WordPress themes’ on Google. And you get results as per the following image.

Experts say that there are high chances that you will click on the Second (2nd) Search Result instead of First (1st).
Though, both the search results’ title start with digits.
But, the 2nd result also highlighted the Current Year and everybody wants to read newer information first. That’s why most of us would likely to click on the 2nd Search result.
At this point, you may argue that I’ll also read the date on which the article gets published and then choose the link.
I would say, Yes, this could be one of the deciding factors in this case, but most of the times there will be only one or two results with the current year or any kind of digit in the result titles.
And the study further reveals that Article Titles with Digits or Years got more clicks in comparison to the Titles without Digits.
I am hoping that now you have agreed with my point.
How you should Add Dynamic Year in WordPress Post Titles
So, we have learned that Digits and Figures are important and we should use the same in our Article Title. But how… what is the correct way out???
One can simply Add Current Year i.e. 2019 in the article title while writing it. Like I have added Year in this blog post related to Best Free CDN Providers for WordPress in 2019, Go check that out.
But what about after one year?
Suppose, you will get a Search Result in Jan 2019 with the Post Title mentioned 2018. Will you click on that search result?
Well, for me, it depends. My first preference would be any other latest search result instead of last year’s result. And, if I am not wrong, most of us will do the same.
People tend to give less importance to older information instead of new information.
So, next year, I have to update the post title manually to stay in the race. Right??
What if, your post title change automatically, and displays the current year instead of the old year.
How about adding a Dynamic Year in Post Title…??? or Add Current Year in WP Post title using shortcode..?? or change WordPress page title dynamically..?? That would be awesome… no…??
Hence, here I am sharing How to Auto Add Dynamic Year in WordPress post title using the WordPress post title shortcode method. These steps will help you to change WordPress page title dynamically.
- First, you need to Activate shortcode for Post Title in WordPress,
- Also, Activate shortcode for Yoast SEO Title and Meta Description (optional, if you are using the Yoast plugin).
- And then create a shortcode, which dynamically displays current year,
- Now, add Current Year in WP Post title using the shortcode.
How to Activate shortcode in WordPress Post Title
You need to add the following code into the functions.php file to activate WordPress post title shortcode:
//* Activate shortcode function in Post Title add_filter( 'the_title', 'do_shortcode' );
The above-given code adds a filter to the_title WordPress Function, which allows you to use the shortcode in WordPress Title. Now, we’ll create a shortcode to display the current year dynamically.
How to Activate shortcode in Yoast Title and Meta Description
The process to use the shortcode in Yoast Title and Meta Description is similar to the use of shortcode in WordPress Post Title. Add the following code in function.php to do the same.
//* Activate shortcode function in Yoast Title and Meta Description add_filter( 'wpseo_title', 'do_shortcode' ); add_filter( 'wpseo_metadesc', 'do_shortcode' );
Now, let’s learn how to add dynamic Year/Month/Date/Day in WordPress post/page title.
How to Auto Add Dynamic Year in WordPress Post Titles
Again, add the given below code in the functions.php file of your WordPress theme:
//* Shortcode to display the current year in WordPress //* shortcode: [year] add_shortcode( 'year' , 'current_year' ); function current_year() { $year = date("Y"); return "$year"; }
Alright, now add this shortcode [year] in your post title and it will auto add Dynamic Year in WordPress Post/Page Titles.
At the backend, in WordPress post editor, your post title would look like…
Fastest WordPress Theme of [year]
And at the front end, your post title would look like…
Fastest WordPress Theme of 2019
If you want to add the day and month along with the year, please use the modified code below.
//* Shortcode to display the current date, month and year in WordPress //* shortcode: [date_month_year] add_shortcode( 'date_month_year' , 'current_date_month_year' ); function current_date_month_year() { $year = date("Y"); $month = date("M"); $date = date("D"); return "$date, $month, $year"; }
Final Code to add in function.php
Let’s compile all the code here… to auto add dynamic yeat in WordPress
//* Shortcode to display the current date, month and year in WordPress //* shortcode: [date_month_year] add_shortcode( 'date_month_year' , 'current_date_month_year' ); function current_date_month_year() { $year = date("Y"); $month = date("M"); $date = date("D"); return "$date, $month, $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
Bonus Tip – How to Add WordPress Copyright Year via Shortcode
Similar to the above-discussed functionality, you can also add a dynamic year in WordPress Copyright. Use the following code to add WordPress copyright year via shortcode.
//* 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"; }
The output of the code would be – © 2019
Use Custom Date and Time formatting
If you want to customize the formatting of date, month or year i.e. use ‘March’ (in full) instead of ‘Mar’. Here are the codes you can use for the same.
# Custom formatting for Year
- “Y” – Capital Y to display 4 digits (Numeric) year i.e. 2019, 2020
- “y” – Small y to display 2 digits (Numeric) year i.e. 19, 20
# Custom formatting for Month
- “M” – Capital M to display 2 letters month i.e. Mar, Apr
- “F” – Small M to display full word month i.e. March, April
- “m” – Small m to display month in digits with leading zeros (Numeric) i.e. 03, 04, 11, 12
- “n” – Small y to display month in digits without leading zeros (Numeric) i.e. 1, 2, 3, 10, 11
# Custom formatting for Day
- “S” – Capital S to display the day of the month with the English suffix (st, nd, rd or th) i.e. 1st, 2nd, 3rd, 4th, 15th
- “d” – Small d to display day in digits with leading zeros (Numeric) i.e. 01, 02, 25, 30
- “j” – Small j to display day in digits without leading zeros (Numeric) i.e. 1, 2, 3, 20, 31
By default, WordPress offers a couple of other Dates and Time formats, which can be used. Read more here for details.
Wrapping it Up
I do Auto Add Dynamic Year in WordPress Post Titles on various blogs using the shortcode in WordPress Post Title. Do you use this trick on your WP blog? or you might find this information useful and plan to give it a shot.
I would recommend you to go ahead and give it a try. You can also modify this code for the customized shortcode you want to use in Post Title. Because the possibilities here are endless.
Do let me know if you face any issue to Add Current Year in WP Post title using the shortcode.
Happy blogging!!!
Further readings…
Hi Saurabh,
I want to be able to add, in addition to a year, also current month. Also I want to be able to append the year only to the post from certain categories. How do I do that?
Thank you!
Hey Darius,
I have modified the code as per your need… use the following code to display Current month and year (Feb, 2018).
//* Shortcode to display the current month and year in WordPress
//* shortcode: [month_year]
add_shortcode( 'month_year' , 'current_month_year' );
function current_month_year() {
$year = date("Y");
$month = date("M");
return "$month, $year";
}
You can use the
is_category
to display in certain categories.Cheers!
Hi Which shortcode will be used to show month and year as you use [year] in the above post I want to show month and year in my post title.
Hey Shaid,
You can use the current month with the year. Here is the modified code.
//* Shortcode to display the current month and year in WordPress
//* shortcode: [month_year]
add_shortcode( 'month_year' , 'current_month_year' );
function current_month_year() {
$month = date("M");
$year = date("Y");
return "$month, $year";
}
I wonder that changing post tile manually affects Seo badly or not. For example I have XYZ 2017 and want to make it XYZ 2018. If I want to make it manually I will go to post in dashboard and just make 2017 => 2018, right? I want to ask you one more question. What about if I remove the year? What happens then?
Hi Alaba,
It totally depends upon what you are changing in the post title. Changing year in the post tile manually or automatically should not affect SEO.
Hi, I know this is not at all what you were going for in this post, but how would you change this to show the static date that it was posted?
I’m trying to crib together posts that name themselves using the date in the title in an automated post. I’m guessing the command to change is “current_year” but don’t know where to go from there.
Hey Saurabh!
Thanks for the snippet, no doubt very useful =)
I add the filter for Yoast, so it can be used in the title of the page as well:
add_filter( ‘wpseo_title’, ‘do_shortcode’ );
Thanks!
Great! Thanks for improvising the snippet.
Hello Saurabh.
Thank you for your code.
Is there a way to display current year also in the meta description of post/page? How will the code look like?
Hello Saurabh.
Thank you for your code.
Is there a way to display current year also in the meta title and meta description of post/page? How will the code look like?
Add the below code with the snippet. It will allow you to use shortcode in yoast title and meta description.
add_filter( 'wpseo_title', 'do_shortcode' );
add_filter( 'wpseo_metadesc', 'do_shortcode' );
Hi,
Thank you for this article!
Can I use this method for the standard page? I’d like to automatically update the year within the text on the standard page.
Thank you for your help!
Yes. Off course.
Hello Alaba,
Really cool stuff. It was very helpful.
I had another query though. What if we wanted to add dynamic day which changes automatically from what is defined for a specific year.
For example:
if the year changes to 2019, my date should change to 1st May
if the year changes to 2020, my date should change to 5th June
if the year changes to 2021, my date should change to 12th June
Thank you in advance 🙂
Hey Sushant, You can use the current date with month and year. Here is the modified code.
//* Shortcode to display the current date, month and year in WordPress
//* shortcode: [date_month_year]
add_shortcode( 'date_month_year' , 'current_date_month_year' );
function current_date_month_year() {
$year = date("Y");
$month = date("M");
$date = date("D");
return "$date, $month, $year";
}
Nice and knowledgeable post.
Hi there,
Thanks for the great code guys!
I am unable to get it the shortcode [month_year] to work with WordPress and Yoast titles. Could you please let me know if my code needs tweeking? It shows [month_year] not Mar 2019
//* Shortcode to display the current month and year in WordPress
//* shortcode: [month_year]
add_shortcode( ‘month_year’ , ‘current_month_year’ );
function current_month_year() {
$year = date(“Y”);
$month = date(“M”);
return “$month, $year”;
}
add_filter( ‘wpseo_title’, ‘do_shortcode’ );
add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ );
Kind regards
Sam
Hi again,
Now it works in wordpress title but not Yoast titles and descriptions 🙁
Please help
Thanks
Sam
My full code is below:
//* Shortcode to display the current month and year in WordPress 2019 starts
//* [month_year]
//* Activate shortcode function in Post Title
add_filter( ‘the_title’, ‘do_shortcode’ );
add_filter( ‘wpseo_title’, ‘do_shortcode’ );
add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ );
add_shortcode( ‘month_year’ , ‘current_month_year’ );
function current_month_year() {
$year = date(“Y”);
$month = date(“M”);
return “$month, $year”;
}
Just to let you know that these 2 lines are creating 1000s of errors
add_filter( ‘wpseo_title’, ‘do_shortcode’ );
add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ );
[21-Mar-2019 20:39:18 UTC] PHP Warning: Use of undefined constant ‘do_shortcode’ – assumed ‘‘do_shortcode’’ (this will throw an Error in a future version of PHP) in /home/website/public_html/wp-content/themes/theme/functions.php on line 1182
I hope you can help.
Sorry for sending 3 posts.
Thanks
Sam
Hey Sam, Your code seems fine and it should work.
The only problem here is, the single inverted comma you are using in your code is incorrect. use ( ‘ ) instead of ( ‘ ).
Copy the code from the post, it will work.
And always use a code editor to edit any code, instead of any text editor, to avoid such mistakes.
I forgot to ask. Would it be possible to have the full word of the month e.g. (March) instead of just short abbreviation e.g. (Mar)
It would be great if you can adjust and repost the code here.
Nice work, thanks for that 🙂
Sam
Hey Sam, I have updated the post as per your request, please check.
Thanks Saurabh,
I didn’t notice that. I’ve just copied and pasted the code from above.
Amazing how a small thing can cause major issues!
Everything is working like a charm now!
Many thanks again 🙂
Sam
Great tips, thank you so much 🙂
great post, really!
one question, how to translate date language from english to italian?
hi how can translate date format from english to italian?
Great post Saurabh!
I modified your code to replace month in my language (the language of the website), hope could be useful:
//* Shortcode to display the current date, month and year in WordPress
//* shortcode: [date_month_year]
add_shortcode( ‘date_month_year’ , ‘current_date_month_year’ );
function current_date_month_year() {
$year = date(“Y”);
$month = date_i18n(“F”);
$date = date(“j”);
return “$date $month $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
Glad you find the code useful. Thanks, Jacopo for sharing the modified code.
Hi, I’m using all in one seo not yoast seo, so how to use this code? Please help. Thank you
Hey Shyam, Use the following filter for All in One SEO.
add_filter(‘aioseop_title’, ‘do_shortcode’); //activate shortcode in All in One SEO Title
add_filter(‘aioseop_description’, ‘do_shortcode’); //activate shortcode in All in One SEO Meta Description
Hope it helps.
Yoast already has a snippet for the year, so nothing extra is needed for that part. However, your tips are great and helped me quickly get the year into Post Titles. Thanks!
Yost has depreciated the year snippet. So, here is the workaround. Thanks for stopping by.
Thank you for this post. Now that all questions and answers were provided, can you please summarize all these in a single video? That will be of further help. Thank you very much.
It’s Great you find it helpful. Thanks for the tip, will definitely look into it.
Glad, you stopped by!
Great its work on posts but how to use it on Category, Tag and page title?
Hey David,
You can use the snippet at almost everywhere in WordPress.
Just allow the use of shortcode using a filter hook. In this case, use the following hooks…
add_filter( 'wp_title', 'do_shortcode' ); // activate shortcode in WP Title - Page or Post
add_filter( 'term_name', 'do_shortcode' ); // activate shortcode in all category, tag and custom taxonomy title
add_filter( 'term_description', 'do_shortcode' ); // activate shortcode in all category, tag and custom taxonomy descriptions
add_filter( 'the_category', 'do_shortcode' ); // activate shortcode in all category title
add_filter( 'category_description', 'do_shortcode' ); // activate shortcode in all category descriptions
add_filter( 'the_tags', 'do_shortcode' ); // activate shortcode in all tag title
add_filter( 'post_tag_description', 'do_shortcode' ); // activate shortcode in all tag descriptions
Hope it help.
i believe we need this for open graph and the schema?
those are giving [month] and [year] outputs. I figured it out for OG:
add_filter( ‘wpseo_opengraph_desc’, ‘do_shortcode’ );
add_filter( ‘wpseo_opengraph_title’, ‘do_shortcode’ );
but haven’t for schema, any ideas?
Thanks, herb.
Please refer to the following code to use the shortcode in OG and Schema output by Yoast.
For OpenGrap –
add_filter( 'wpseo_opengraph_title', 'do_shortcode' );
add_filter( 'wpseo_opengraph_desc', 'do_shortcode' );
For Schema –
add_filter( 'wpseo_json_ld_output', 'do_shortcode' );
Hello sourav, thanks for this awesome guide.
I am using only astra theme and Yoast SEO plugin on my blog.
But the [year] shortcode is not working in schema only.
I already added this code to functions.php:
add_filter( ‘wpseo_json_ld_output’, ‘do_shortcode’ );
But it is not working with the webpage name section in the schema graph.
“@type”: “WebPage”,
“@id”: “http://example.com/first-post#webpage”,
“url”: “http://example.com/first-post”,
“name”: “How to buy best iPhone [year]”,
Any ideas how to solve this problem?
I have a question. Will post title dynamic year be automatically change after a year Or i have to change manually.
What I was really looking for. However, I am using RankMath SEO plugin, so I use the following short codes:
1)
add_filter( ‘rank_math/frontend/title’, function( $title ) {
return $title;
});
add_filter( ‘rank_math/frontend/description’, function( $description ) {
return $description;
});
2)
add_filter( ‘rank_math/frontend/title’, function( $title ) {
//create some conditional logic here to execute the below for only certain pages/posts
$title = do_shortcode($title);
return $title;
});
How to add the same hook for the site’s search results titles?