Answer the question
In order to leave comments, you need to log in
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');
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');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question