Shoora
5/3/2019 - 5:48 AM

Add parent cat_name_in_title Yoast SEO

Add parent cat_name_in_title Yoast SEO

add_filter('wpseo_replacements', 'city_wpseo_replacements');

function city_wpseo_replacements( $vars ) {
	global $wp_query;
	$cat = get_category(get_query_var('cat'),false);
	$cat_parent = $cat->parent;
	$cat_name = get_the_category_by_ID( $cat_parent );
	if ($cat_parent) {
		$cat_name = get_the_category_by_ID( $cat_parent );
	} else {
		$cat_name = '';
	}
	
    $vars['%%parent_cat_title%%'] = $cat_name;
    return $vars;       
}