Wait—some people are still updating the year of their guides manually in 2023?!

Share this:

It’s that time of year again—the holidays are right around the corner, and affiliate marketers all around the globe are gearing up to switch out the current year for next year on all of their content. And just like Christmas, which seems to come around earlier each year, many affiliates are already making the switch to 2023 in a bid to get the jump on competitors.

The prompt to create this post was a reply on Twitter from Google’s John Mueller, who was poking fun at the sites that do this, calling them out for being obvious spam—the tweet is embedded below for reference:

While I don’t want to chime in too much on the topic, I think it’s pretty unfair to jump to the conclusion that these sites are spam, for two reasons really. The first is that not all niches are consumer electronics—there are plenty where there isn’t a brand new, must-have product released every five minutes. For niches like these—where products from 2-3 years ago are still going to be the best—what kind of content updates are Google looking for beyond the current year?

The second is all the big name sites that have jumped on the bandwagon, publishing “best X of [current year]” articles and ranking for them with ease, based on the overall authority of their sites. Names like Forbes, the New York Times, and the Wall Street Journal all do this—the WSJ even have guides on “the best toys” which rank—when exactly did they become the go-to authority on toys?! Are these the “low-quality, spam sites” that Google is talking about, or do a different set of rules apply to these types of sites than to those of us mere mortals? I don’t know, but there’s an interesting discussion to be had there.

As I said at the beginning—not really going to get into any of that here—this article is more in response to my surprise that there are people out there manually updating their articles this way. What a waste of time!

Stop updating the year manually! Here’s one method you can use

The main point of this article is to highlight that manually updating the dates on your various product reviews and buying guides each and every year is stupid—there are plenty of ways to automate this, with the example I’m going to show in this article being just one route you could go down.

This example uses a humble shortcode, letting you add in the current year into the main body of your articles and content, as well as the page titles and meta descriptions, with support for several popular SEO WordPress plugins built-in.

Keep in mind that to use this you will need to do a find and replace on your database eitherway—so, given that this is a once-a-year task, you might be happier sticking with that. For me personally, I went down this route because it was a pretty easy five minute job, but it might be a little bit overkill for many.

That said, it works for me—and it was super easy to write and implement, so why not really. If you’re someone interested it modifying titles and meta descriptions programmatically with any of the main WordPress SEO frameworks, the working snippets of how to set these should be of interest even if you don’t opt to implement this shortcode solution to the problem of updating the current year.

The code

It’s pretty simple—the plugin creates a short code that returns the current year, then uses filters and regex to replace the same shortcodes used in page titles and meta descriptions.

The shortcode for this example is:

[the_current_year/]

It simply needs to be used as-is in the page title and meta description fields. Excuse the incredibly poor content in the examples below:

Page title description:

Some awesome page title about the best something in [the_current_year/] - Site Name

Page meta description:

Some awesome meta descruption about the best something in [the_current_year/]. Find reviews, images, and whatever else, blah blah blah.

The example plugin includes a conditional statement that determines which of the three most popular SEO WordPress frameworks you have installed—these being “The SEO Framework“, “Yoast“, and “Rank Math”—using the “is_plugin_active()” function to find out which is active.

I’ve included the respective snippets of each below for reference:

The SEO Framework

if(is_plugin_active('autodescription/autodescription.php')) {
    add_filter('the_seo_framework_title_from_custom_field',function($title) {
        if($title) {
            return the_current_year_title_filter($title);
        } else {
            add_filter('the_seo_framework_title_from_generation', 'the_current_year_title_filter', 10, 2);
        }
    }, 10, 2 );
    add_filter('the_seo_framework_custom_field_description', function($description) {
        if($description) {
            return the_current_year_title_filter($description);
        } else {
            add_filter('the_seo_framework_generated_description', 'the_current_year_title_filter', 10, 2);
        }
    }, 10, 2 );
} 

Yoast

else if(is_plugin_active('wordpress-seo/wp-seo.php')) {
    add_filter('wpseo_title', 'the_current_year_title_filter', 10, 2);
    add_filter('wpseo_metadesc', 'the_current_year_title_filter', 10, 2);
}

Rank Math

 else if(is_plugin_active('seo-by-rank-math/rank-math.php')) {
    add_filter('rank_math/frontend/title', 'the_current_year_title_filter', 10, 2);
    add_filter('rank_math/frontend/description', 'the_current_year_title_filter', 10, 2);
}

Beyond that, there’s not a lot more to understand really. The plugin uses filters on the title before the page is rendered, using regex to replace the shortcode with the actual date using preg_replace. It’s not overly complicated—but in all fairness, it’s not all that complex of a task.

The whole file can be seen below—just copy and paste it from here.

plugin.php

<?php
/**
* Plugin Name: The current year
* Plugin URI: https://www.duinobit.com
* Description: Plugin for getting the current year as a shortcode and filtering page titles and meta descriptions
* Version: 1.0
**/

function the_current_year_shortcode() {
    if (!is_admin()) {
        $year = date("Y");
        return $year;
    }
}
add_shortcode('the_current_year', 'the_current_year_shortcode');

function the_current_year_regex_filter($text) {
    $string = $text;        
	$pattern = '[\[the_current_year /\]]';
    $replacement = date("Y");
    return preg_replace($pattern, $replacement, $string);
}

function the_current_year_heading_filter($text) {
	return the_current_year_regex_filter($text);
}
add_filter('the_title', 'the_current_year_heading_filter', 10, 2);

function the_current_year_title_filter($text) {
	return the_current_year_regex_filter($text);
}

if (!function_exists('is_plugin_active')) {
    include_once(ABSPATH . 'wp-admin/includes/plugin.php');
}

if(is_plugin_active('autodescription/autodescription.php')) {
    add_filter('the_seo_framework_title_from_custom_field',function($title) {
        if($title) {
            return the_current_year_title_filter($title);
        } else {
            add_filter('the_seo_framework_title_from_generation', 'the_current_year_title_filter', 10, 2);
        }
    }, 10, 2 );
    add_filter('the_seo_framework_custom_field_description', function($description) {
        if($description) {
            return the_current_year_title_filter($description);
        } else {
            add_filter('the_seo_framework_generated_description', 'the_current_year_title_filter', 10, 2);
        }
    }, 10, 2 );
} else if(is_plugin_active('wordpress-seo/wp-seo.php')) {
    add_filter('wpseo_title', 'the_current_year_title_filter', 10, 2);
    add_filter('wpseo_metadesc', 'the_current_year_title_filter', 10, 2);
} else if(is_plugin_active('seo-by-rank-math/rank-math.php')) {
    add_filter('rank_math/frontend/title', 'the_current_year_title_filter', 10, 2);
    add_filter('rank_math/frontend/description', 'the_current_year_title_filter', 10, 2);
}

How to use it

The first thing to keep in mind is that this won’t magically replace all of the existing dates in your site—as you’ll first need to replace these with the shortcode.

To do this, you’ll want to use something like Better Search Replace—which basically lets you run a search and replace on your database, replacing instances of “2022” with “the_current_year” shortcode, given again below for reference.

[the_current_year/]

There are a few additional steps to get it up and running, which I’ve outlined below:

  • Copy and paste the “plugin.php” file above—putting it into a file of the same name and adding it to a ZIP archive.
  • Upload and install it from the “add plugin” section of WP Admin.
  • That’s it—all setup, ready to use with the shortcode given above.

Summing it up

Well, that’s it—a working example of a simple shortcode solution to the problem of updating article dates each year.

In all honesty, this might not be the most practical solution for everyone, especially since you’ll need to run a search and replace on your database to set it up anyway—which, given how infrequently this task is required, you might be better off running that once a year instead.

This was really about how you might do it and to highlight that if you are someone doing this manually, you really shouldn’t be wasting you time like that—there’s no need to. Personally, I use this on my sites—it’s easier for me, and didn’t take very long to implement, so made sense to do so—but that might not be the case for everyone.

If you do decide to use the example given in this article and have any questions or experience any difficulty while trying to use it, feel free to give me a shout in the comments. Thanks for reading!

Share this:

Leave a Comment