Merge pull request #22554 from woocommerce/fix/seo
Better `@id` generation for product structured data
This commit is contained in:
commit
8c860c65bd
|
@ -195,15 +195,16 @@ class WC_Structured_Data {
|
||||||
$shop_name = get_bloginfo( 'name' );
|
$shop_name = get_bloginfo( 'name' );
|
||||||
$shop_url = home_url();
|
$shop_url = home_url();
|
||||||
$currency = get_woocommerce_currency();
|
$currency = get_woocommerce_currency();
|
||||||
|
$permalink = get_permalink( $product->get_id() );
|
||||||
|
|
||||||
$markup = array(
|
$markup = array(
|
||||||
'@type' => 'Product',
|
'@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(),
|
'name' => $product->get_name(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( apply_filters( 'woocommerce_structured_data_product_limit', is_product_taxonomy() || is_shop() ) ) {
|
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 ) );
|
$this->set_data( apply_filters( 'woocommerce_structured_data_product_limited', $markup, $product ) );
|
||||||
return;
|
return;
|
||||||
|
@ -250,7 +251,7 @@ class WC_Structured_Data {
|
||||||
$markup_offer += array(
|
$markup_offer += array(
|
||||||
'priceCurrency' => $currency,
|
'priceCurrency' => $currency,
|
||||||
'availability' => 'https://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
'availability' => 'https://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
||||||
'url' => $markup['@id'],
|
'url' => $permalink,
|
||||||
'seller' => array(
|
'seller' => array(
|
||||||
'@type' => 'Organization',
|
'@type' => 'Organization',
|
||||||
'name' => $shop_name,
|
'name' => $shop_name,
|
||||||
|
@ -329,12 +330,6 @@ class WC_Structured_Data {
|
||||||
$markup['itemListElement'] = array();
|
$markup['itemListElement'] = array();
|
||||||
|
|
||||||
foreach ( $crumbs as $key => $crumb ) {
|
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(
|
$markup['itemListElement'][ $key ] = array(
|
||||||
'@type' => 'ListItem',
|
'@type' => 'ListItem',
|
||||||
'position' => $key + 1,
|
'position' => $key + 1,
|
||||||
|
|
Loading…
Reference in New Issue