Add word before category title

Hello.
I’m creating a restaurants directory in Spain and the names of the categories are by cities like Madrid, Barcelona, Málaga, etc. But in the category page title instead of Madrid, Barcelona, Málaga… I will need for SEO reasons to be Restaurantes en Madrid, Restaurantes en Barcelona, Restaurantes en Málaga, etc. So I need to add the words “Restaurantes en” before the category name in the category page title. how can I achieve that? I was looking in the templates in order to override it, but could not find any for the category page title.
Thanks in advance, regards.

Hola!

Check the_title wordpress filter.

Hi,

We recommend testing the RankMath plugin, if I’m not mistaken, it has this feature. You just need to enable the listing category in the settings to enable the RankMath SEO features and then put the title with tokens. Another option is a custom implementation.

​I hope this is helpful to you

Hola @cotasson
This is my function, but I’m not sure why it is not working:

// Modify categories title
function modify_categories_title($title) {
    // Check if it is a category page
    if (is_category()) {
        // Get category name
        $categoria = single_cat_title('', false);

        // Customize the title with "Restaurantes en"
        $title = 'Restaurantes en ' . $categoria;
    }

    return $title;
}

// Filter the title with function
add_filter('single_cat_title', 'modify_categories_title');

Looks fine for me. Maybe because is a listing category?

Hi @andrii
I will check the plugin, I’m using now Yoast so maybe could be some conflict problems between them?
And I will like to explore a no plugin solution first, is possible?
Thank you, regards.

I tried to implement the_title() or single_cat_title(), without success either, lo siento.

You may try to have a look at the template hierarchy too, and create your own for categories.

@andrii is right, a good seo plugin would handle this for you right off the bat.
Don’t mix RankMath and Yoast, it’s surefire way of getting into trouble.

Since you are using Yoast, this may help : Yoast SEO settings: Categories & tags • Yoast

Also your post is unclear…
Are you trying to modify the title tag (<title>My title</title>), or the one in between the <h1>My Title</h1> ?

Based on this the solution is different.

For both cases, a good SEO plugin should get you covered.

1 Like

Hi,

Yes, if you have YoastSEO, then they should have this feature available for the taxonomy meta title, then you don’t need to do it with code.

Hello @cotasson and @andrii
Sorry for the delay answer.
You are right @cotasson, my post is unclear, to change the words inside the tag is simple with Yoast or another SEP plugin, I was refering to the h1 Title in the category page, as I said, for example my category name is “Madrid”, but I need the category page h1 title to be “Restaurantes en Madrid”, I need to add before Madrid the words “Restaurantes en”, so the rest of categories will look “Restaurantes en Barcelona”, “Restaurantes en Málaga”… etc, in there respective category page h1 title.

Thanks in advance, regards.

Here’s what I am using, for lack of a better solution : I am injecting some text in the vendor profile title, with javascript.

All my vendor page have a static title ,<h1>Profil</h1>, and I customize it with jQuery :

$(".hp-vendor--view-page h1").append(" de "+  $("h3.hp-vendor__name").text());

I wish I could come up with something better, I am not sure it has any positive impact on SEO, as Google does not read javascript so well.

Improvement welcome !