How to Drive More Organic Traffic from Google by Auto Inserting Month Year in Title?

how to optimize title seo

If you do SEO, you might wanna to add years in title and content. If you are confused of why you do this, just import some keywords with the current year appending into any keyword tool that give the search volume, you might be surprized how many people search a keyword by appending the current year or month to that keyword each month. Those types of keywords tend to be neglected by many SEOers.

Therefore, an experienced SEOer always optimize its article by inserting a current year or month to its title or content. However, what if a year or month has gone? Will you remember to come back and manually edit the new year in the article title? Actually, this is a process that can be automatic by playing a few lines of php codes.

In this article, I will show you how to automatically insert the current year or month in the title or anywhere in the content.

So, you don’t have to manually update the title at the beginning of each year. It would be a very painful process if you have hundreds of articles published on your website.

Automatically Insert the Current Year in the Title – Step by Step Guide

To realize the auto insertion, you need to insert a block of php codes into the functions.php file.

For any custom on functions.php, you always need to create a child theme first, instead of inserting everything straight in the parent theme. Otherwise, the new theme update will overide everything you add in there.

Once you activate your Child theme, go to the Dashboard, then open the Theme Editor from “Appearance” menu on the left sidebar.

Then click the file of “functions.php” on the right panel.

Then insert the following code in the functions.php. Just remember DO NOT close the php with ?>, or it won’t display properly.


/* Activate shortcode function in Post Title */
add_filter( 'the_title', 'do_shortcode' );

/* Activate shortcode function in Yoast Title and Meta Description */
add_filter( 'wpseo_title', 'do_shortcode' );
add_filter( 'wpseo_metadesc', 'do_shortcode' );


/* 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";
}

/* Shortcode to display the current year in WordPress */
/* shortcode: [year] */
add_shortcode( 'year' , 'current_year' );
    function current_year() {
    $year = date("Y");
    return "$year";
}

That’s it. The above code will create a couple of shortcodes that you can use not only in the Post Titles, but also in Yoast’s Meta Title and Meta Description fields and also anywhere inside the article.

To include just the current year in your Title, use the shortcode [year]
To include the current month and year in your Title, use the shortcode [month_year]

Bonus:

The above shortcode [month_year] outputs the month and year as Nov 2020. This is preferable for use in Post Titles since the number of characters that Google can display in the SERPs is limited. However, in your H2s or other locations where you have no such restriction, you can use the full month name and year as November, 2020 with the comma in between as well. For that insert the following code into the same functions.php file and click Update File:


/* Shortcode to display the current month and year in WordPress */
/* shortcode: [long_month_year] */
add_shortcode( 'long_month_year' , 'current_long_month_year' );
function current_long_month_year() {
$year = date("Y");
$month = date("F");
return "$month, $year";
}

To display the full month and year, you can now use the shortcode [long_month_year] anywhere in the article.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *