Mobile app version of vmapp.org
Login or Join
Merenda212

: 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

@Merenda212

Posted in: #Google #Php #Seo #Title #Wordpress

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

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Merenda212

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme