List of available snippet variables in Yoast SEO

List of available snippet variables in Yoast SEO

One of the most important functions of Yoast SEO (free or premium) is the ability to automatically add SEO title and meta description templates to the homepage, all (custom) post types, all (custom) taxonomies, and other pages. We include default templates that are SEO-friendly but you can also modify the default templates.

If you want to know more about what snippet variables are and how Yoast SEO uses snippet variables, you could read this article. Or, to read about how to modify the default snippet template, check out this guide.

Do you know about social previews in Yoast SEO Premium? They work much like the snippet preview, and they allow you to control what your posts look like when shared on social media!

In this article:

Available variable types
Deprecated variables
Default variables
Developer filters
Creating custom template variables

Available variable types

We distinguish four available variable types:

Basic variables
Advanced variables
Custom variables
WooCommerce variables

Basic variables

LabelVariableDescriptionDate%%date%%Replaced with the date of the post/pageTitle%%title%%Replaced with the title of the post/pageParent title%%parent_title%%Replaced with the title of the parent page of the current pageArchive title%%archive_title%%Replaced with the normal title for an archive generated by WordPressSite title%%sitename%%The site』s nameTagline%%sitedesc%%The site』s taglineExcerpt%%excerpt%%Replaced with the post/page excerpt (or auto-generated if it does not exist)Excerpt only%%excerpt_only%%Replaced with the post/page excerpt (without auto-generation)Tag%%tag%%Replaced with the current tag/tagsCategory%%category%%Replaced with the post categories (comma separated)Primary category%%primary_category%%Replaced with the primary category of the post/pageCategory description%%category_description%%Replaced with the category descriptionTag description%%tag_description%%Replaced with the tag descriptionTerm description%%term_description%%Replaced with the term descriptionTerm title%%term_title%%Replaced with the term nameSearch phrase%%searchphrase%%Replaced with the current search phraseSeparator%%sep%%The separator defined in your theme』s wp_title() tag.

Term template variables are used with custom taxonomies. If you do not have a custom taxonomy use either the tag or category template variables.

Advanced variables

The following sample of variables requires a better understanding of SEO. If you』re unsure how to use these advanced variables, we advise you not to use them. You can learn more about SEO, in our online Yoast SEO academy courses.

LabelVariableDescriptionPost type (singular)%%pt_single%%Replaced with the content type single labelPost type (plural)%%pt_plural%%Replaced with the content type plural labelModified%%modified%%Replaced with the post/page modified timeID%%id%%Replaced with the post/page IDName%%name%%Replaced with the post/page author』s 『nicename』User description%%user_description%%Replaced with the post/page author』s 『Biographical Info』Page number%%page%%Replaced with the current page number with context (i.e. page 2 of 4)Pagetotal%%pagetotal%%Replaced with the current page totalPagenumber%%pagenumber%%Replaced with the current page numberCaption%%caption%%Attachment captionFocus keyword%%focuskw%%Replaced with the posts focus keyphraseTerm404%%term404%%Replaced with the slug which caused the 404 (custom field)%%cf_%%Replaced with a posts custom field value. Remove the (custom taxonomy)%%ct_%%Replaced with a posts custom taxonomies, comma separated. Remove the description (custom taxonomy)%%ct_desc_%%Replaced with a custom taxonomies description. Remove the

Custom variables

The last three advanced variables can be used to output data from non-standard WordPress elements, such as WooCommerce products. But, how do you find the name of the correct field or taxonomy to use these variables?

Custom fields

Custom field names can be found using the steps here. Once you have the custom field name, you will replace . If my custom field was calledmyfield, the custom variable would be %%cf_myfield%%. Or, if the custom field begins with an underscore, for example _anotherfield, the custom variable should include the underscore like so: %%cf__anotherfield%%.

Note: Custom fields that contain arrays (a list of related information) will not work with the custom field variable. Instead, you or your developer should create your own custom template variables.

Custom taxonomies

Custom taxonomy names can be found in the browser bar on the backend when viewing or editing an item.

Example: edit-tags.php?taxonomy=mycategory&post_type=myposttype

In the example above, we are editing a custom taxonomy called mycategory under a custom post type called myposttype. If I wanted to output a list of categories assigned to a myposttype page, I would use %%ct_mycategory%%. Alternatively, if I wanted to output the description of an individual mycategory on the category archive page, I would use %%ct_desc_mycategory%% .

WooCommerce variables

The following variables are some that you can use with WooCommerce. If the specific variable you are looking for is not listed below, please use the custom variable information above to find the variable you need.

%%ct_product_cat%%Product category (comma separated)%%ct_product_tag%%Product tag (comma separated)%%ct_pa_%%Product attribute (comma separated). Be sure to remove the as they are not needed.

Yoast WooCommerce SEO variables

When you are using our Yoast WooCommerce SEO plugin, these additional variables are available:

%%wc_shortdesc%%Replaced with the short description of the product. (Available as of Yoast WooCommerce SEO 6.2)%%wc_sku%%Replaced with the inventory stock-keeping unit (sku) of the product. (Available as of Yoast WooCommerce SEO 6.2)%%wc_brand%%Replaced with the brand name. This variable only works with 『WooCommerce Brands『 and 『Perfect WooCommerce Brands『 plugins. (Available as of Yoast WooCommerce SEO 6.2)%%wc_price%%Replaced with price of the product. (Available as of Yoast WooCommerce SEO 6.2)

Deprecated variables

Starting in v7.7 of Yoast, we』ve deprecated these variables as we see no valid use-case for them. If they are used in the snippet editor, they won』t appear in the snippet preview. However, they will show up in your source code to maintain backward compatibility. We recommend not using them.

%%userid%%Replaced with the post/page author』s userid%%currenttime%%Replaced with the current time%%currentdate%%Replaced with the current date%%currentday%%Replaced with the current day%%currentmonth%%Replaced with the current month%%currentyear%%Replaced with the current year

Default variables

If you want to reset the SEO title template variables back to the defaults use the following below.  For meta descriptions the default is blank. You can enter these default titles in the SEO-Search Appearance section. This will then assign the defaults as the global template variable for that section.

%%title%% %%page%% %%sep%% %%sitename%%%Posts, Pages, Products, Media, and Custom Post Types%%pt_plural%% Archive %%page%% %%sep%% %%sitename%%
Posts, Products, and other Custom Post Type Archive Pages%%term_title%% Archives %%page%% %%sep%% %%sitename%%TaxonomiesYou searched for %%searchphrase%% %%page%% %%sep%% %%sitename%%Special Pages: Search PagePage Not Found %%sep%% %%sitename%%Special Pages: 404 Pages%%name%%, Author at %%sitename%% %%page%%Author Archive Pages%%date%% %%page%% %%sep%% %%sitename%%Date Archive PagesThe post %%POSTLINK%% appeared first on %%BLOGLINK%%.RSS Feed %%sitename%% %%page%% %%sep%% %%sitedesc%%Homepage Template

There are a number of filters documented in the plugin code for developers to programmatically change the template variables. Here are some examples.

Creating custom template variables

Adding your own template variables can be done using the wpseo_register_extra_replacements filter in your functions.php file. An example of how to use the filter can be viewed here.

You might not want Yoast to show these Yoast-created titles. In that case, you can use these filters here. If you are not sure how to add or use filters, consider working with a Yoast partner.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注