Hello,
Thank you for contacting Rank Math.
You need to replace Rank Math with the actual brand name.
For example, if the brand name is Google, the code should look like this:
/**
* Filter to add custom Brand for WooCommerce Products.
*/
add_filter('rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
$entity['brand'] = 'Google';
return $entity;
}
);
I hope this helps.
Thank you.
But each product could have different Brand. I need a more dynamic option. I’m labeling the brand with the woocommmerce option and every product has is own brand.
Hello,
Could you please let us know how would you set a specific brand for each of your products?
Instead of adding a static string in the filter code, you can return your product’s brand by getting its meta value. You can follow this guide for that: https://developer.wordpress.org/reference/functions/get_post_meta/
Or, if your brand is based in taxonomy, you may refer to this guide as well: https://stackoverflow.com/questions/56276674/how-to-get-the-brand-name-of-product-in-woocommerce
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hello. I got a better solution. I simply check the brand name in the text and use that to set the brand with IF
/**
* Filter to add custom Brand for WooCommerce Products.
*/
add_filter('rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
if (strpos(get_the_title( $post_id ),'Zippo') !== false) {
$entity['brand'] = 'Zippo';
} elseif (strpos(get_the_title( $post_id ),"Casio") !== false) {
$entity['brand'] = "Casio";
} elseif (strpos(get_the_title( $post_id ),"Q&Q") !== false) {
$entity['brand'] = "Q&Q";
} elseif (strpos(get_the_title( $post_id ),"Seiko") !== false) {
$entity['brand'] = "Seiko";
} elseif (strpos(get_the_title( $post_id ),"Citizen") !== false) {
$entity['brand'] = "Citizen";
} elseif (strpos(get_the_title( $post_id ),"Parker") !== false) {
$entity['brand'] = "Parker";
} elseif (strpos(get_the_title( $post_id ),"Blitz") !== false) {
$entity['brand'] = "Blitz";
} elseif (strpos(get_the_title( $post_id ),"Connoisseurs") !== false) {
$entity['brand'] = "Connoisseurs";
} else {
$entity['brand'] = "Rank Math";
}
return $entity;
}
);
Hello,
I am glad you are able to find a workaround for that.
If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.