The Trick behind adding Dynamic Year in Blog Articles TITLE!


#1

I remember updating a status update on Facebook like:

December 31st, 2016: Best 2016 SEO Tips for Bloggers!

January 1st, 2017: Best 2017 SEO Tips for Bloggers!

Just a few seconds difference, 2016 becomes 2017… I know this is kinda unethical to change the year without actually updating the article.

If you search for anything with the word ‘Best,’ ‘Top,’ ‘Upcoming,’ etc… then Google will automatically include the current year along with it.

If you feel like the content (like tips, listicles, etc.) is suitable for the next year as well, then here is a trick which will help you to save time and optimize your articles for SEO.

Dynamic Year Trick (WordPress)

This PHP code works on WordPress blogs, so go to your Dashboard > Theme Editor > functions.php file.

Add this code snippet for enabling post meta shortcode:

//* Enable Post Meta Shortcode Support

add_filter( 'single_post_title', 'do_shortcode' );

Add this code snippet for enabling post title shortcode:

//* Enable Post Title Shortcode

add_filter( 'the_title', 'do_shortcode' );

Now, add this code snippet for enabling dynamic year:

//* Current Year In Post Title Shortcode

add_shortcode( 'year' , 'current_year' );

    function current_year() {

    $year = date("Y");

    return "$year";

}

After adding these, just save the file. Now, whenever you want to make a list post or top/best article like “Top 10 Horror Movies in 2017” or “Best Technologies We Are Looking Forward In 2018” (When you publish this next year), all you need to do is…

Add [year] in the title, just like how we did here:

This is very simple to implement and reflects the current year. If you take a look at the first picture, I would have used ‘best-android-smartphone’ permalink slug instead of ‘best-android-smartphone-in-2017’, it’ll help to keep my permalinks clean, and I don’t need to edit them every year whenever it changes.

UPDATE: This might cause issues for post meta titles, so if you are using Yoast SEO plugin, then use %%currentyear%% instead of [year] there.

Thanks @shrivant and @mskian.

Do try this small tweak and let us know if you face any issues. :slight_smile:


#2

In case, you’re looking to add dynamic title only for the SEO Title (Title Tag and SERP), you can use Yoast for this.

While adding a new post, Edit your Yoast Snippet , SEO Title with the following phrases:

seo title

%%currentmonth%% - For Current Month
%%currentyear%% - For Current Year


#3

Thanks for it. :slight_smile: this is what I did after seeing this post.

image

Here is code for current month & year: [month]

//* Current Month & Year In Post Title Shortcode

    add_shortcode( 'month' , 'current_month' );

        function current_month() {

        $month = date("F, Y");

        return "$month";

    }

This is for current date [date]

//* Current Date In Post Title Shortcode

add_shortcode( 'date' , 'current_date' );

    function current_date() {

    $date = date("jS F Y");

    return "$date";

}

#4

We can manually do it for best/top posts isn’t it?


#5

Yes, you can manually do this for such posts. :slight_smile:


#6

bro did you notice your post meta title it display as shortcode


#7

Which one bro? :open_mouth: Can you share a screenshot, please?


#8

here bro check meta title

msk-demo-test-hbb1

solution add this below line too

// Enable Post Meta Shortcode Support
add_filter( 'single_post_title', 'do_shortcode' );

#9

Thanks bro, will check this, also updated another tweak for this. :slight_smile:


#10

Convert them into plugin :slight_smile:

HBB Dynamic Post Title Dates

  • Create a New Folder named as - hbb-post-title-date-year
  • inside the Folder create a PHP File named as - hbb-post-title-date-year.php
  • Copy and paste the below code into that file and save it
  • Next, Compress that folder into Zip file
  • goto Wordpress Dashboard
  • plugins > Add New > Upload Plugin > install & Activate it
<?php
	
/*
Plugin Name: HBB Dynamic Post Title Dates
Plugin URI: https://forum.hellboundbloggers.com/t/the-trick-behind-adding-dynamic-year-in-blog-articles-title/2560
Description: A Simple Plugin which Help is to add Title, Date and Year Dynamically on WordPress posts via shortcode.
Author: HBB Fellows
Author URI: https://forum.hellboundbloggers.com
Version: 1.0
License: GNU General Public License v2.0 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: hbb-post-title-date-year
*/

// Enable Post Title Shortcode
//add_filter( 'the_title', 'do_shortcode' );

// Enable Post Meta Shortcode Support
//add_filter( 'single_post_title', 'do_shortcode' );

// Enable shortcodes in text widgets
//add_filter('widget_text', 'do_shortcode');

// It will Enable shortcode support for Post title, Meta title and Text widgets
add_filter('single_post_title', 'hbb_dynamic_postdates' );
add_filter('the_title', 'hbb_dynamic_postdates' );
add_filter('widget_text', 'hbb_dynamic_postdates');
function hbb_dynamic_postdates( $title ){
    return do_shortcode( $title );
}

// Current Year In Post Title Shortcode - https://forum.hellboundbloggers.com/u/pradeepkumar
// shortcode: [year]
add_shortcode( 'year' , 'current_year' );
    function current_year() {
    $year = date("Y");
    return "$year";
}

// Current Month & Year In Post Title Shortcode - https://forum.hellboundbloggers.com/u/Hitesh
// shortcode: [month]
    add_shortcode( 'month' , 'current_month' );
        function current_month() {
        $month = date("F, Y");
        return "$month";
    }

// Current Date In Post Title Shortcode - https://forum.hellboundbloggers.com/u/Hitesh
// shortcode: [date]
add_shortcode( 'date' , 'current_date' );
    function current_date() {
    $date = date("jS F Y");
    return "$date";
}

  • Shortcodes
[year] - Display Current year
[date] - Display Current date
[month] - Display current month

Credits - @pradeepkumar @Hitesh


#11

This is AWESOME bro! Thanks for sharing this! :heart_eyes:


#12

Great Article. Thank You for sharing this.


#13

@pradeepkumar as we are using IntellWP Pro plugin it’s creating an issue. IntellWP plugin is showing the shortcode.

If anyone knows how to fix it then please let us know. Thanks in advance.


#14

Can you kindly share a screenshot, please? :slight_smile:


#15

@pradeepkumar Niche site, not possible to reveal it, sorry. :smiley:


#16

Okie bro, but I want to know what issue it is causing exactly? Where do you see the shortcode exactly?


#17

@pradeepkumar bro whenever we are using the IRP plugin shortcode, in output it’s showing [year] in the title (that related post box).


#18

add this below line & check

// Enable Post Meta Shortcode Support
add_filter( 'single_post_title', 'do_shortcode' );

#19

@mskian Thanks but I already added it.


#20

it displays as shortcode on related postbox?