T
T
tbalero2016-05-01 08:50:49
Search Engine Optimization
tbalero, 2016-05-01 08:50:49

How to add custom variable (for Yoast WordPress SEO plugin) - for custom taxonomy term?

There is a WordPress site.
To add a custom variable (for the Yoast WordPress SEO plugin) for custom post types - I use this code in the functions.php file and it works correctly:

function get_meta_for_title_of_metro() {
 return get_post_meta(get_the_ID(), 'title-of-metro', true);
}
function register_custom_extra_replacements() {
 wpseo_register_var_replacement( '%%title-of-metro%%', 'get_meta_for_title_of_metro', 'advanced', 'it is custom field' );
}
add_action('wpseo_register_extra_replacements', 'register_custom_extra_replacements');

*In this case, we have:
- custom field: title-of-metro
- custom variable (for the Yoast WordPress SEO plugin): %%title-of-metro%%
.....
In the case of custom taxonomy terms, I try to use a similar the code. get_post_meta();*In the code I use instead get_term_meta();- but this code does not work correctly - as a result, it is not possible to get the value of the custom field title-of-metro and pass it to the custom variable (for the Yoast WordPress SEO plugin) %%title-of-metro%% :
function get_meta_for_title_of_metro() {
 return get_term_meta(get_the_ID(), 'title-of-metro', true);
}
function register_custom_extra_replacements() {
 wpseo_register_var_replacement( '%%title-of-metro%%', 'get_meta_for_title_of_metro', 'advanced', 'it is custom field' );
}
add_action('wpseo_register_extra_replacements', 'register_custom_extra_replacements');

Question: How can I modify this code (in functions.php file) to add a custom variable (for Yoast WordPress SEO plugin) - for custom taxonomy term?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mibo, 2016-12-15
@mibo

Yoast WordPress SEO allows you to customize meta tag templates for taxonomy terms. I don’t see the point of adding additional features.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question