Cyber Monday Mega Sale! + USD $16k Worth of discounts!

LIMITED TIME OFFER!
  1. Home
  2. Knowledge Base
  3. SEO Suite
  4. Set the Current Year in Post Title Using The [year] Shortcode

Set the Current Year in Post Title Using The [year] Shortcode

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.

Navigate to 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.

Choose rank-math.php file in child theme

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' );
Add code snippet in rank-math.php file

3 Update the File

Finally, click the Update File button at the bottom of the screen.

update rank-math.php file

Now you can try using the [year] shortcode in your post title.

Year shortcode in Post Title

Your post title and SEO title in the front end will be replaced with the current year.

Year shortcode being replaced with 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…

Was this article helpful?

Still not using Rank Math?

Setup takes less than 5 minutes including the import from your old SEO Plugin!

Learn more about the PRO Version

Still need help?

?

Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket

Related Articles