-
Good day, esteemed support.
I have this question.
There are categories of goods and brands of goods. I need that when the brand filter is applied in the category this resulting url needs to be indexed.
For example:
Category: Bass guitars
In this category there are 4 brands: Harley Benton, Gibson, ESP, FenderI want such brands in this category to be indexed:
1) Bass guitars + Harley Benton
2) Bass guitars + Gibson
3) bass guitars + ESP
4) Bass guitars + FenderYou should get pages like this with titles:
1)Bass Guitars Harley Benton Buy Best Price | Sitename
2)Bass guitars Gibson Buy Best Price | Sitename
3)Bass guitars ESP Buy Best Price | Sitename
4)Bass guitars Fender Buy Best Price | SitenameCan you tell me how to do this with your plugin?
Regards Denis.
Translated with http://www.DeepL.com/Translator (free version)
-
Hello,
Thank you for contacting Rank Math for help with creating custom page titles with your post categories and brand names.
Rank Math allows you to automatically create page titles with your post category names as part of the title. You can follow this guide for how: https://rankmath.com/kb/titles-and-meta/. To include brand names in the post title, you will have to create a custom title variable; this requires some coding skills. You can follow this guide for how to create a custom title variable: https://rankmath.com/kb/variables-in-seo-title-description/#how-to-add-custom-variables
Hope that helps. Please let us know if you have questions.
Hi!
Thank you very much for the quick response.
I implemented what I wanted, but for some reason I have the brand name with a small letter all.
How do I make the brand name appear as it is on the site?
Here’s an example of what it looks like now:
Category page:
https://soundsmag.com/product-category/guitars-and-basses/electric-guitars/double-cut-guitars/Category + brand page:
https://soundsmag.com/product-category/guitars-and-basses/electric-guitars/double-cut-guitars/?filter_brand=epiphoneHere is the code I made:
add_filter( ‘rank_math/frontend/title’, function( $title ) {
if( is_product_category() ) {
$filter_brand = $_GET[‘filter_brand’];
$space = ‘ ‘;if ( isset($filter_brand) ) {
$title = $filter_brand . $space . $title;
}
}
return $title;
});And tell me how to index only these filters (Category + Brand) and the rest of the price and others to prohibit indexing?
Regards Denis.
Sincerely Denis.
Hello,
You can set the filter brand to uppercase by using the
ucfirst()
function from PHP on that variable: https://www.php.net/manual/en/function.ucfirst.phpAs for the canonical of those pages, you would need to edit the following filter to make sure the URL of the canonical matches the URL on the page on the filter pages: https://rankmath.com/kb/filters-hooks-api-developer/#change-canonical-url
Don’t hesitate to get in touch if you have any other questions.
Hi!
Thanks for the reply.
I was able to solve the issue with the Capital letters in the brand.But I don’t understand how to make the filter canonical.
I added this code
/**
* Allow changing of the canonical URL.
*
* @param string $canonical The canonical URL.
*/
add_filter( ‘rank_math/frontend/canonical’, function( $canonical ) {
return $canonical;
});But if you open the site code, the page category is still canonical, not the filter which is applied by the brand.
Can you tell me what I’m doing wrong?
Regards Denis.
Hello,
Please try adding this filter to force the self-referencing canonical URL with filtered pages:
add_filter( 'rank_math/frontend/canonical', function( $canonical ) { $canonical = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; return $canonical; });
Once done, clear your website’s cache and check again.
Let us know how this goes.
Thank you.
Hi!
Thank you so much!
It worked.But now I have another question.
How to make the canonical URL be only with Brand filter
For example:
https://soundsmag.com/product-category/keys/stage-pianos/?filter_brand=clavia-nordAnd the other filters that would not be canonical.
For example:
https://soundsmag.com/product-category/keys/stage-pianos/?min_price=150&max_price=3330
https://soundsmag.com/product-category/keys/stage-pianos/?orderby=date&paged=1
https://soundsmag.com/product-category/keys/stage-pianos/?orderby=price&paged=1
https://soundsmag.com/product-category/keys/stage-pianos/?orderby=price-desc&paged=1
https://soundsmag.com/product-category/keys/stage-pianos/?orderby=popularity&paged=1Best Regards Denis
Hello,
In this case, you would need to modify the filter a bit.
Please refer to this code instead:
add_filter( 'rank_math/frontend/canonical', function( $canonical ) { $url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if(strpos($url,'?filter_brand=') !== false){ return $url; } return $canonical; });
Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.
Hi!
Thank you so much!It worked!
Can I ask you another question, how do these pages that come out with the brand filter now add to the sitemap?
Or how to send them all to Google?
Regards Denis.
Hello,
By default, our sitemap only adds actual pages or posts and not dynamic pages such as the filter pages on your website. To add it to your sitemap you need to manually add it using this filter: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-urls-in-sitemap
I would suggest just letting Google discover these types of URLs as forcing many URLs that are not often visited may cost you unnecessary crawling budgets. However, if you believe these URLs are always visited by your users, then you can go ahead and add them to your sitemap or use the Instant Indexing feature.
Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.
Hello.
I add the code to the site that you indicated, but it does not work for some reason.
I create a file in the root of the topic: rank-math.php and tried to add to function.php
I add the code there:
/** Filter to add extra URLs to the XML sitemap by type. * Only runs for the first page, not on all. * @param string $content String content to add, defaults to empty. */ add_action( 'rank_math/sitemap/page_content', function() { return '<url> <loc>https://rankmath.com/some-custom-url/</loc> <lastmod>2020-06-10T20:20:20+00:00</lastmod> </url>'; });
What am I doing wrong?
Regards Denis.
Hello,
I’ve checked your page sitemap, and indeed the sample URL is not getting included.
Please follow the steps below for initial troubleshooting:
1. Flush the Sitemap cache by following this video screencast:
https://i.rankmath.com/pipRDp2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
https://rankmath.com/kb/exclude-sitemaps-from-caching/If the issue still persists, please try adding this filter to your active theme’s functions.php file:
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
Let us know how this goes.
Thank you.
Hi! That helped.
I now have this url in my Page folder. (https://rankmath.com/some-custom-url/)
Link to the sitemap: https://soundsmag.com/page-sitemap.xml
How do I make all the pages with the Brand filter appear there now?
Example:
https://soundsmag.com/product-category/cables-and-connectors/cable-drums/?filter_brand=schill
It turns out a lot of such pages, and how do I automatically add them all to the sitemap?
Regards Denis.
Hello,
Unfortunately, this process could not be automated and needed to include each brand-filtered URL in the code/filter you’re using.
However, since they are already set to index, they are not required to be included in your sitemap like my colleague mentioned above. They can be discovered using different methods like internal linking as well.
Looking forward to helping you.
Thank you.
Thank you very much for the clarification.
Now it all makes sense to me how it works.
Regards Denis.
Hello,
Glad that helped.
If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.
Looking forward to helping you.
Thank you.
The ticket ‘Index woocommerce category + woocommerce attribute’ is closed to new replies.