Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon what are some examples of custom template variables in Yoast SEO


what are some examples of custom template variables in Yoast SEO


Here are some examples of custom template variables that can be used in Yoast SEO:

1. %%myname%%: This is a custom variable that can be used to output the sentence "My name is Moses" in the front-end. The code to register this custom variable is:

php
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');

function get_myname() {
    return 'My name is Moses';
}

function register_custom_yoast_variables() {
    wpseo_register_var_replacement('%%myname%%', 'get_myname', 'advanced', 'some help text');
}

2. %%pt_plural%%: This variable can be used to output the plural form of the post type in the SEO title template for post type archive pages.

3. %%POSTLINK%%: This variable can be used in the RSS feed template to link back to the original post.

4. %%BLOGLINK%%: This variable can also be used in the RSS feed template to link back to the blog.

5. %%searchphrase%%: This variable can be used in the SEO title template for the search results page.

6. %%name%%, %%date%%: These variables can be used in the SEO title template for author archive pages and date archive pages respectively.

7. %%term_title%%: This variable can be used in the SEO title template for taxonomy archive pages.

The search results also mention that developers can create their own custom template variables using the `wpseo_register_extra_replacements` filter in WordPress. This allows for a high degree of flexibility and customization in how Yoast SEO generates SEO titles and meta descriptions.

Citations:
[1] https://yoast.com/yoast-seo-snippets-to-customize-your-site/
[2] https://yoast.com/features/meta-tag-variables/
[3] https://yoast.com/help/list-available-snippet-variables-yoast-seo/
[4] https://documentation.wilcity.com/knowledgebase/how-to-add-custom-fields-to-yoast-seo-meta-tags/
[5] https://developer.yoast.com/customization/yoast-seo/adding-custom-data-analysis/