To add custom variable (for Yoast WordPress SEO plugin) - for posts of custom post type I use in my functions.php this code, and it's work 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 I have:
-
custom field: title-of-metro
-
custom variable (for Yoast WordPress SEO plugin): %%title-of-metro%%
.....
In a case with custom taxonomy term I try to use analogycal code. *Instead get_post_meta(); I try to use get_term_meta(); - but this code work incorrectly (can't get value of custom field 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 to change this code (in functions.php), to add custom variable (for Yoast WordPress SEO plugin) - for custom taxonomy term?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire