Filter function for wordpress seo title

924 Views Asked by At

I do SEO for a client of mine and we use a plugin to showcase cars, getting the data from Mobile.de.

Now this plugin takes the cars name e.g. "Nissan X-Trail 1.75 dCi 4x4 AT TEKNA BOSE+STANDHEIZ+AHK" and puts the wordpress blogs name "- Kallies Automobile e.K. | Einfach. Sicher. Autofahren. ✔️" right behind it. Here's the URL, if it helps: https://kallies-automobile.de/

I want to get rid of the blog name and tried using a str_replace function

add_filter(DXIM_FILTER_VEHICLE_SINGLE_PAGE_TITLE,function($title, $vehicle) {
    $title = str_replace('- Kallies Automobile e.K. | Einfach. Sicher. Autofahren. ✔️', '', $title); {
 }
 return $title;
},10,2);

But it's not working at all. I'm happy for input!!!

1

There are 1 best solutions below

2
On

It looks like you're using Yoast SEO, so in that regard you would want to use the Yoast SEO page title filter:

add_filter('wpseo_title', 'filter_post_title');
function filter__title($title) {
    if( is_singular( 'fahrzeugangebot' ) ) {
        $title = str_replace('- Kallies Automobile e.K. | Einfach. Sicher. Autofahren. ✔️', '', $title);
    }
    return $title;
}

That filter above checks to see if we're in a single post of the post type 'fahrzeugangebot' (apologies if this isn't quite what you're trying to achieve) and then does the str_replace that you put in.