Это решение, которое возвращает город и штат, поскольку вы выбрали только одну таксономию (город) и этот штат является прямым родителем города. Я думаю, что вместо get_terms()
вы хотите использовать get_the_terms()
function get_state() {
global $post;
// Get the terms for the current post in your tax
$myterms = get_the_terms( $post->ID, 'w2dc-location' );
// Check if parent exists
if ($myterms[0]->parent !== 0){
// Get the term object
$parent = get_term_by('id', $myterms[0]->parent, 'w2dc-location');
return $parent->name;
}
}
function register_custom_yoast_variables() {
wpseo_register_var_replacement( 'state', 'get_state', 'advanced', 'some help text' );
}
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');
Использование в поле заголовка Yoast ...
%%category%% %%state%%