Woocommerce: Dynamic header with attributes on category page (with ranking math)
P粉155551728
P粉155551728 2024-01-10 16:40:38
0
1
442

I have an online store with product category pages. The latter features filters to reorganize products according to the user's preferences. Among these filters, some are interesting from an SEO point of view, such as the possibility to select only products of a specific brand.

Just, after doing this, the URL of the category page does change to "?filter_brand=brandname", but the title (and h1 btw) is still the same as the original category page. This is very annoying when it comes to SEO.

I understand that with the Yoast SEO plugin, this change is automatic:

https://www.welaunch.io/en/knowledge-base/faq/woocommerce-seo-filter-titles/ (example of title and h1 changing based on color filter, exactly what I'm looking for )

With Rank Math (the SEO plugin I use), this is not done automatically, but it is possible to add a code snippet that can modify the page title. this one:

add_filter( 'rank_math/frontend/title', function( $title ) {
    return $title;
});

However, being low level in PHP, I don't know what variables to modify in order to modify the title of a specific page, or automatically modify the title like Yoast SEO does (which works for me given the number of variables and category pages).

According to my observation, when I modify this code, all the pages of my website have the title "Test":

add_filter( 'rank_math/frontend/title', function( $title ) {
    $title="test";
    return $title;
});

I think these are basic changes, but I can't find any way to make the $title function work for a specific page rather than the entire site. Better yet, make him understand that the title must contain the variable "Brand Name" visible in the URL, just like Yoast SEO, so that you don't have to rewrite the code 100 times by modifying the variable each time.

So this is a long cobblestone for something that's not very rocket science, but at my low level this is a real dilemma...if anyone has a solution, even It's the leader, I'm very interested. Thanks!

P粉155551728
P粉155551728

reply all(1)
P粉129731808

You can view the answer to this questionLink. As mentioned there, first check if you are in the product category archive, if so then get the current term name of the product category page and set it to $title and return it. If it works, please let me know in the comments.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!