Merge pull request #22554 from woocommerce/fix/seo

Better `@id` generation for product structured data
This commit is contained in:
Mike Jolley 2019-01-31 13:47:08 +00:00 committed by GitHub
commit 8c860c65bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 9 deletions

View File

@ -195,15 +195,16 @@ class WC_Structured_Data {
$shop_name = get_bloginfo( 'name' );
$shop_url = home_url();
$currency = get_woocommerce_currency();
$permalink = get_permalink( $product->get_id() );
$markup = array(
'@type' => 'Product',
'@id' => get_permalink( $product->get_id() ),
'@id' => $permalink . '#product', // Append '#product' to differentiate between this @id and the @id generated for the Breadcrumblist.
'name' => $product->get_name(),
);
if ( apply_filters( 'woocommerce_structured_data_product_limit', is_product_taxonomy() || is_shop() ) ) {
$markup['url'] = $markup['@id'];
$markup['url'] = $permalink;
$this->set_data( apply_filters( 'woocommerce_structured_data_product_limited', $markup, $product ) );
return;
@ -250,7 +251,7 @@ class WC_Structured_Data {
$markup_offer += array(
'priceCurrency' => $currency,
'availability' => 'https://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'url' => $markup['@id'],
'url' => $permalink,
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
@ -329,12 +330,6 @@ class WC_Structured_Data {
$markup['itemListElement'] = array();
foreach ( $crumbs as $key => $crumb ) {
// Don't add the current page to the breadcrumb list on product pages,
// otherwise Google will not recognize both the BreadcrumbList and Product structured data.
if ( is_product() && count( $crumbs ) - 1 === $key ) {
continue;
}
$markup['itemListElement'][ $key ] = array(
'@type' => 'ListItem',
'position' => $key + 1,