Awesome Way to Add [CURRENT YEAR] in Wordpress Post Title
How to Add a Dynamic Year to Your WordPress Post Title and Yoast Meta Data
Do you write reviews or " Best of " posts? I am going to share with you a tip that can greatly reduce future blog maintenance.
Studies show that Meta titles displayed in search results that have the current year displayed in title get more clicks. It makes your post seem up to date. And people want current information.
The last few weeks I have verified through my own research this is the case. Post that have the year in the title get more traffic from search engines. The problem with adding the year to your post and meta titles is that you have to update after a new year begins. This can be time-consuming. Going back to every post and changing the title, meta title and description is a daunting task.
A Quick and Easy [short code] Solution Without Adding A New Pluggin
What if I told you that you can add a [short code] in your title and metadata that would automatically change the year, date and time if you wanted it to? Would this save you time? Sure would.
This is a little advanced and requires changes to your theme coding, but it is relatively simple. And I am going to show you step by step. So don't worry.
1. First Step- Login into you WordPress admin. Go to Appearance and select Theme Editor
Step 1 will bring to the theme editor page. It should look similar to the picture below.
2. Step 2- Next step is to click on the "functions.php" file as pictured above. This will take you to functions.php as pictured below.
3. Step 3- On the side of caution we will backup the original functions.php file. Just encase you mess up or something goes wrong. To do this you need to highlight the code in your functions.php file, copy and save it into a text editor like Word or something similar.
This way you have a backup just in case. Do as pictured below. If you do need to go back to the original functions.php file, just past your saved code back into your functions.php file and click update file at the bottom left. This will restore the file to its original code.
4. Step 4- Make sure your functions.php code is not highlighted any longer. Scroll down to the bottom of the functions.php code. Click on the last, empty line of code and press enter to create a space between the last line of code and your cursor. This gives you a clean and easy to find place to insert the extra code we will be adding. Check out the image below for a visual of what I am referring to.
5. Step 5- Highlight the code below, copy and paste it into the function.php file at the bottom where your cursor is. Then Click "Update File" at the bottom left corner as pictured below.
Copy and Paste This Code
//* Activate Dynamic Year shortcode function in Post Title
add_filter( 'the_title', 'do_short code' );
//* Activate Dynamic Year short code function in Yoast Title and Meta Description
add_filter( 'wpseo_title', 'do_short code' );
add_filter( 'wpseo_metadesc', 'do_short code' );
//* Shortcode to display the current year in WordPress
//* short code: [year]
add_short code( 'year' , 'current_year' );
function current_year() {
$year = date("Y");
return "$year";
}
//* Shortcode to display the current date, month and year in WordPress
//* short code: [date_month_year]
add_short code( '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_short code' ); // activate short code in WP Title
add_filter( 'wpseo_title', 'do_short code' ); // activate short code in Yoast Title
add_filter( 'wpseo_metadesc', 'do_short code' ); // activate short code in Yoast Meta Description
6. Step 6- That is all on modifying your themes code. Now we move onto adding the short code to your post. To add the year to your post title you need to just add a little short code in the title. The short code is [year]. If you want to add the date in your YOAST meta description you can add the short code there also.
7. Step 7- If you are using Yoast SEO Plugin, it will automatically add your title to your meta title. The short code will automatically be in Yoast Meta Title as pictured below.
That's it. Here is how it looks in the Search Engine Results
I hope you enjoy and can utilize this time saving WordPress Hack. Good Luck!
Recent Comments
9
This is really great info, Adam! It makes sense that people click on articles that are more recent. It wasn't until you said it that I realized I look for a date when googling something because I want up-to-date information, not from 2013 for example.
Thanks a lot for sharing!
All the best
Melissa
See more comments
I read that real quick Affiliate Marketing Guy!
Saved it to my favourites. Good idea. Just not there yet with building out my site.
But I will be and I will be using a few Best of...
Great information about the date, makes sense.
Appreciate your post Adam.
Here's wishing 🧞♂️ you a wonderful day.
Louise