Last active
September 4, 2023 12:51
-
-
Save wp-seopress/58272742bd6a1c4b9beb58ac580c1e75 to your computer and use it in GitHub Desktop.
Dynamic variable for SEOPress: get term parents list of the current term taxonomy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sp_titles_template_variables_array($array) { | |
$array[] = '%%parent_terms_title%%'; | |
return $array; | |
} | |
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array'); | |
function sp_titles_template_replace_array($array) { | |
$queried_object = get_queried_object(); | |
$term_id = $queried_object->term_id; | |
$tax = $queried_object->taxonomy; | |
$args = [ | |
'format' => 'name', | |
'separator' => ', ', | |
'link' => false, | |
'inclusive' => false | |
]; | |
$ancestors = get_term_parents_list($term_id, $tax, $args); | |
if ($ancestors && is_string($ancestors)) { | |
$array[] = esc_attr(wp_strip_all_tags($ancestors)); | |
} | |
return $array; | |
} | |
add_filter('seopress_titles_template_replace_array', 'sp_titles_template_replace_array'); | |
function sp_get_dynamic_variables($array){ | |
$array['%%parent_terms_title%%'] = __('Parent terms title', 'my-text-domain'); | |
return $array; | |
} | |
add_filter('seopress_get_dynamic_variables', 'sp_get_dynamic_variables'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment