: How to create an SEO friendly custom post type title using Yoast I have used this code to filter $title of a custom post type, and it works perfectly fine when there are search results on
I have used this code to filter $title of a custom post type, and it works perfectly fine when there are search results on the post type e.g A query for Mercedes Benz cars for sale in Paris would show a $title like this Mercedes Benz used cars for sale in Paris on Sitename
add_filter('wpseo_title', 'vehicle_listing_title');
function vehicle_listing_title( $title )
{
if ( get_post_type() == 'vehicles' )
{
$location = get_the_terms($post->ID, 'vehicle_location');
$model = get_the_terms($post->ID, 'vehicle_model');
$title = $model[0]->name . 'used cars for sale in' . $location[0]->name .'on'. get_bloginfo('name');
}
return $title;
}
But then again, when there aren’t any search results on the post type, the code returns a single term title e.g A query for Mercedes Benz cars for sale in Paris would show a $title like this Mercedes Benz archives – Sitename I need this to return filtered $title for all search queries, because I have a sitemap pulling these Urls from the custom post type.
I need this to function for SEO reasons. I want to avoid duplication of titles, because it will affect rankings.
I’ve been struggling with this for some time now.
Any help would be appreciated
More posts by @Merenda212
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.