Yoast SEO Custom Template Variable

Post Reads 16 reads

In this article we are going to see how to add custom template variable into the Yoast SEO plugin.

We are going to read:

What are the variables in Yoast? What are the variables in Yoast?

Yoast plugin provides the variables to customise the site title. Below are some examples of the variables.

  • %%title%%
  • %%sitename%%
  • %%title%%
  • %%primary_category%%
  • %%sep%%
  • etc

You can see all available variables at:

We can customize the title tag with the help of above variables.

Example of using variables into the title tag Example of using variables into the title tag

Below is the example screenshot of the variables.

Suppose when we use the variables:

%%title%% %%page%% %%sep%% %%sitename%%
Hello world! - Dev

Here,

  • Hello world! – Is my post title.
  • (Dash) – Is a Separator
  • Dev – Is my site name.

How to add custom variables? How to add custom variables?

WordPress SEO Yoast plugin provide the function wpseo_register_var_replacement which allow us to add custom variables.

Let’s add current year and current month variable to add into the title variable.

How to add the current Month variable? How to add the current Month variable?

Simply copy and paste below code snippet into your child themes functions.php file.

And use the variable %%current_month%% into the title.

Example Usage

%%title%% %%current_month%% %%sep%% %%sitename%%

The title tag is generated as below:

<meta property="og:title" content="Hello world! May - Dev" />

We can see the current month May into the title variable.

How to add the current Year variable? How to add the current Year variable?

Simply copy and paste below code snippet into your child themes functions.php file.

And use the variable %%current_year%% into the title.

Example Usage

%%title%% %%current_year%% %%sep%% %%sitename%%

The Title tag is generated as below:

<meta property="og:title" content="Hello world! 2020 - Dev" />

We can see the current month 2020 into the title variable.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
%d bloggers like this: