According to a study, humans’ eyes don’t tend to read all the letters one by one, especially on the internet. Instead, it looks out for highlighted words, numbers, and bullet points.
Out of these three, numbers make the most impact on the human brain. Digits or figures stand out among other texts, which is what has inspired studies that have proven that numbers are a trigger to get your visitors to pay attention to your content. Article titles with digits or years get more clicks than titles without digits. Rank Math makes it very simple to automatically add the current year in your post with the help of a shortcode.
In this knowledgebase article, we’re going to walk you through how to set the current year in the post title using [year] shortcode.
How to Set the Current Year in Post Title Using [year] Shortcode
Before using the [year] shortcode in the post title, you need to add a code snippet as discussed below.
1 Navigate to Theme File Editor
Start by heading over to Appearance β Theme File Editor (for Classic Theme) inside your WordPress admin area. In case of a Block Theme head over to WordPress Dashboard β Tools β Theme File Editor.
And, then choose rank-math.php (you can create the file if you haven’t already) from the list of theme files shown on the right side of the screen. Alternatively, you can choose the functions.php file to add the code snippet.
2 Add the Code Snippet
In the code editor, that appears in the middle of your screen, copy and paste the following code snippet.
// Create Year shortcode to replace with current year.
add_shortcode( 'year', 'current_year' );
function current_year() {
$year = date( 'Y' );
return $year;
}
// To allow Rank Math Frontend title to parse shortcode.
add_filter(
'rank_math/frontend/title',
function ( $title ) {
return do_shortcode( $title );}
);
// Activate shortcode function in Post Title.
add_filter( 'the_title', 'do_shortcode' );
3 Update the File
Finally, click the Update File button at the bottom of the screen.
Now you can try using the [year] shortcode in your post title.
Your post title and SEO title in the front end will be replaced with the current year.
Note: When using the [year] shortcode in Title as described in the tutorial, you don’t need to use the variable again in your Rank Math Titles & Meta. Doing so will result in the current year being shown twice. Also, it’s normal if the preview snippet doesn’t show the year, however, if you check the source code of the live page, the year will be correctly displayed.
If you still have questions about setting the current year in post title using [year] shortcode β you’re always more than welcome to contact our dedicated support team, who are available 24/7, 365 days a yearβ¦