I make a lot of searches on Google for WordPress related plugins, themes, and general knowledge. Through the years, I’ve noticed a trend where authors of blog posts include the current month or year in their post titles, headings, and content. I’ve often wondered how they do that. I understand that it’s simple to physically type the current year into a post, but what happens when the year changes from one to the next? Do all these authors revisit every single post they’ve ever written to update the year? For the longest time, I couldn’t believe that could be the case. Now, I know better.
Before I go any further, please allow me to give you an example of what I’m referring to. Take a look at these sample search results. I searched Google for “best WordPress themes.”
Notice the 2024 in the results. Why is that there and how does it dynamically change? Those, along with a few other questions will be answered in this post. By the time you’re finished reading what I write on this page, you’ll have the knowledge necessary to add your own dynamic dates to your own WordPress blogs. The process is straightforward and very simple to complete. It’s totally painless.
Why Are Dynamic Dates Important for WordPress Posts?
There’s been a popular trend recently to add numbers to blog post titles and headings. Here are a few examples:
15 Ways to Make Your Blog More Popular
37 of the Best WordPress Themes Available Today
The rationale behind this sort of thing suggests that humans are attracted to numbers. Just as humans tend to believe anything that’s written, likewise, humans tend to click on search results and take more credence in specifics. So a title like, “The Best WordPress Themes Available,” wouldn’t hold nearly the same level of attractiveness as one that contains a specific, such as the number 37, as in 37 WordPress Themes…
Numbers that describe what a post contains is wonderful, but what about a month or a year that describes how current a post is? As you read above, adding the current year to a blog post is now fashionable as well. Why? Because humans tend to gravitate toward the most recent information available. Whether or not adding the current year to a blog post’s title results in additional traffic is debatable, but the empirical evidence suggests it is. The trend is growing. Nearly half the searches I made today for WordPress related information contained the current year. It’s a real thing.
Simply put, adding numbers and the current year in blog post titles and headings are attractive and can result in more traffic to a blog post.
How to Add Dynamic Dates Via Yoast & RankMath
Now that I’ve made the case for adding the current year into a blog post title and headers, how can we add them so they update dynamically, meaning, how can the year change all by itself? The answer to this question is clear and the process of making the change is simple. Read below for instructions for adding the dynamic year via Yoast and RankMath.
Dynamic Years Via Yoast
Yoast is the most popular WordPress SEO plugin on the planet. It outranks RankMath in downloads by 6.5x at any given moment. This isn’t to say that RankMath isn’t absolutely awesome, because it is. It’s definitely a favorite among users and some folks swear by it.
All of this is neither here nor there as it pertains to adding dynamic years and months to blog posts. To do so, simply scroll to the Yoast SEO section on the Add New Post page and add either %%currentmonth%% for the dynamic month and/or %%currentyear%% for the dynamic year. These snippets would be added to the SEO Title field, wherever you’d like to see them. Mind you, this technique is limited to showing dynamic dates in only the title or description fields, not in the post itself. For that, you’ll need to employ a different tactic. See below.
Dynamic Years Via RankMath
RankMath is the second most popular SEO plugin on earth today. It enjoys a highly committed userbase and is incredibly effective to work with. While not as popular as Yoast, its downloads are climbing in number.
To add a dynamic month or year to the RankMath plugin, do the exact same thing as described above in the Yoast section. Simply add %currentmonth% and/or %currentyear% inside of the title and/or description fields and you’ll see the dates appear in those sections of the post. Again, like Yoast, this tactic is only available for title and meta description areas of the post, not for body and headers.
How to Add Dynamic Dates Via Your Theme
In this section, I’ll explain how to go about activating short codes in your WordPress theme and then how to go about employing them in your posts. I don’t actually recommend using this method, as it’s long-winded and cumbersome. It also becomes difficult to deal with when changing themes. The overall method I do suggest I show in the next section below. But for the sake of posterity, I’ll explain this long and arduous method now.
To start off, you’ll first need to tell WordPress that you’d like to use short codes in your post titles. You’ll need to activate short codes in your functions.php file in your theme. Navigate to Appearance > Theme File Editor in your admin area and then click the functions.php file link. Once inside the file, scroll all the way to the bottom on the file and then press your Enter key twice to give you some room. Then add this line:
add_filter( 'the_title', 'do_shortcode' );
Below the above line, add this code:
add_shortcode( 'year' , 'current_year' );
function current_year() {
$year = date("Y");
return "$year";
}
Once complete, press the Update File button down below and then go ahead and add the [year] short code to your post and page titles. This short code should update automatically as each year changes to the next.
If you’d like to add the month along with the year, add this code to the file instead of the code directly above:
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";
}
Again, I don’t advocate for using this method for the reasons I gave above. For the easiest way to add dynamic months and years to your posts, please see below.
How to Add Dynamic Dates Via a Plugin
Why in the world would someone go through the trouble of editing theme code when they could simply install a plugin that does all the work for them? If you’re looking to add dynamic months and years to your posts and pages, this is the best method to use.
There’s a wonderful plugin available that’s called, “Dynamic Month & Year into Posts” and it can be found here. This plugin can handle all of your dynamic date needs along with so much more. Just some of what it can do is:
- Add today’s date by [date]
- Current year by [year]
- Previous year by [pyear]
- 2 years back from this year [ppyear] (read previous-previous year)
- Next year by [nyear]
- 2 years from this year [nnyear] (read next-next year)
- Current month by [month]
- Next month by [nmonth]
- Previous month by [pmonth]
- Etc…
The plugin is compatible with just about everything, including:
- Rank Math (100%)
- Rank Math Pro (100%)
- SEOPress
- SEOPress Premium
- Yoast SEO
- Yoast SEO Premium
- Etc…
And a lot more. To see the list, click here. To review the entire list of short codes and other tips, click here. By far, this is the easiest and most effective option for adding dynamic dates to your WordPress blog posts and pages.
Conclusion
I hope I’ve helped with your endeavor of adding dynamic dates to your WordPress blog. If you have any questions or comments regarding this topic, please leave them below. Thanks for reading!
Leave a Reply