-
Hello,
all of a sudden the Google Search console gave me warnings for missing brand and gtin. I used code to modifiy it, i found it here in the forum. Any ideas how to fix this?
Following code is used:
/**
* Filter to replace wc_brand with custom value.
*/
add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
if ( is_singular( ‘product’ ) ) {
$product = wc_get_product();$brand = $product->get_attribute(‘pa_hersteller’);
// Use this code to get 1st element from brand attribute if multiple brands are assigned to a Product.
$brands = explode( ‘,’, $brand );
if ( ! empty( $brands ) ) {
$entity[‘brand’] = $brands[0];
}
}
return $entity;
});
/**
* Filter to modify schema data.
* @brand for products
* @param array $entity Snippet Data :
* @return array
*/
add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
$entity[‘offers’][‘priceValidUntil’] = ‘2099-12-31’;
$entity[‘gtin13’] = str_replace(‘-‘, ”,$entity[‘gtin’]);
return $entity;
});
add_filter( “rank_math/snippet/rich_snippet_product_entity”, function( $entity ) {
global $product;if ( is_a( $product, ‘WC_Product’ ) ) {
$entity[‘gtin13’] = WC_trusted_shops()->trusted_shops->get_product_gtin( $product );
}return $entity;
});
The ticket ‘missing “brand” and “gtin” in Google Search Console’ is closed to new replies.