how to use dynamic month year

How to Use Dynamic Year and Month in your Post Title and Content?

how to use dynamic month year

Have you seen blog articles with SEO titles containing the year?

It would be 15 Best WordPress Customization Plugins To Improve Your Website’s Design in 2022.

But this blog title requires the admin to change year after year. Manually changing the year would require the admin to remember and edit it. Not doing so will result in the same year appearing in the Google search results.

This post will show you how to add dynamic year and month in your post title and content.

There are two methods to use dynamic year and month.

Using these tricks, you will save a lot of time in changing the month and year into posts dynamically. 

Why Should You Add Dynamic Year and Month In Your Post Title and Content?

It’s a human tendency to give importance to the text that shows importance. Numbers quickly strike our mind as it shows importance. Similarly, when you insert a year in the title, it shows its importance in that particular year.

Human eyes don’t read all the text and give importance to highlighted words and numbers.

A human brain is always looking for the current year’s information. Therefore, the year plays a vital role in the title. 

E.g., you searched for the best Elementor themes on Google.

Below is the result after searching on Google:

month year google search

If you see the results, you will find the first two results starting with a number. This is eye-catching, but the second result from wpbeginner slides into your mind.

So why would you click on the second result, not the first one?

This is because the second result is updated to the year 2022. Also, the date is updated; therefore, users tend to click on the second result.

What we wanted to convey to you is that numbers play a significant role in Google search results. Articles with digits drive more clicks compared to others.

How To Add Dynamic Year and Month In WordPress Post Title and Content?

We have already learned the importance of numbers in the title and content. We can simply add the year 2022 in the article and inside the content. But what after that?

After a year, it wouldn’t change automatically. 

Here’s the best way to dynamically add month and year in your post SEO title:

You might use an SEO plugin like Yoast SEO or RankMath Pro for your blog post. 

For Yoast SEO:

Simply add %%currentmonth%% for adding month dynamically, and %%currentyear%% for adding year dynamically.

For RankMath:

Add %currentmonth% and %currentyear% for adding month and year dynamically in the post. 

But these variables work only for the SEO title. If you insert these variables into the content, it will appear. 

You need to add a shortcode to dynamically add month and year in your content and post title. Another way is to install the WordPress plugin. We will take a look at both these methods.

Adding year and month in the post title and content dynamically

First, activate shortcodes for post titles, and then create a shortcode to display the current year dynamically. 

You can now add the current year in the post title using the created shortcode. 

Activating the Shortcode

Add the following code in your functions.php file:

add_filter( ‘the_title’, ‘do_shortcode’ );

You can also activate shortcodes for Yoast title and meta description. Add the below lines:

add_filter( ‘wpseo_title’, ‘do_shortcode’ );

add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ );

Adding Dynamic year in WordPress post titles

Copy the below lines and paste it in the functions.php file.

add_shortcode( ‘year’ , ‘current_year’ );

    function current_year() {

    $year = date(“Y”);

    return “$year”;

}

Now add the shortcode [year] in your WordPress post title. This will dynamically add year in post and pages automatically. 

Similarly you can add date and month along with the year using the below shortcode.

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”;

}

When we compile all the codes, this is what it looks like:

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

Adding Month and Year Using Plugin

This is a beautiful plugin that works on auto-mode. Simply install and activate the plugin. Once activated, you can add shortcodes inside your WordPress content and post/page titles.

dynamic month year plugin

The plugin supports:

  • Rank Math
  • Rank Math Pro
  • SEOPress
  • SEOPress Premium
  • Yoast SEO
  • Yoast SEO Premium

How To add month and year using a plugin?

  • To add a date, use [date]. 
  • To add the current year, add [year]. 
  • For the previous year, add [pyear].
  • For next year, add [nyear].
  • Use [month] to add the current month and [mon] for the short name of the current month.
  • For RankMath, you can replace %currentmonth% with [month], and %currentyear% with [year].

Conclusion

This trick of dynamically adding month and year in WordPress post titles and year works best for bloggers. As bloggers often publish articles, both methods are a time savior.