title: "Product" post_status: publish comment_status: open taxonomy: category: - yoast-developer post_tag: - Pieces - Schema - Features


import YoastSchemaExample from '../../../../src/components/YoastSchemaExample';

描述企业销售的产品。

触发条件

必需属性

一个有效的 Product 必须包含以下属性。

失败场景

如果任何必填字段缺失或无效,则不应输出该节点。

如果节点未输出,任何原本声明自己属于 Product 的实体都应移除这些引用(例如,与 Product 相关的 Offer)。

可选属性

以下属性应在可用且有效时添加:

示例

最低标准

{{ "@context": "https://schema.org", "@graph": [ { "@type": "Product", "@id": "https://www.example.com/#/schema/Product/abc123", "name": "Example Product", "image": { "@id": "https://www.example.com/uploads/example-image.jpg" } } ] }}

Extended criteria

{{ "@context": "https://schema.org", "@graph": [ { "@type": "Product", "@id": "https://www.example.com/#/schema/Product/abc123", "name": "Example Product", "description": "Example product description", "image": { "@id": "https://www.example.com/uploads/example-image.jpg" }, "offers": { "@id": "https://www.example.com/#/schema/Offer/abc123" }, "brand": { "@id": "https://www.example.com/#/schema/Organization/abc123" }, "manufacturer": { "@id": "https://www.example.com/#/schema/Organization/def456" }, "review": [ { "@id": "https://www.example.com/#/schema/Review/abc123" }, { "@id": "https://www.example.com/#/schema/Review/def456" } ], "sku": "abc123", "aggregateRating": { "@type": "AggregateRating", "ratingValue": "4", "reviewCount": "3077" } } ] }}

Yoast WooCommerce SEO API:修改产品 Schema 输出 {#api}

要修改 Yoast SEO 输出的 Product schema,你可以使用我们的 wpseo_schema_product 过滤器。示例如下:

add_filter( 'wpseo_schema_product', 'example_change_product' );

/**
 * 向产品 schema 添加颜色属性。
 *
 * @param array $data Schema 产品数据。
 *
 * @return array Schema.org 产品数据数组。
 */
function example_change_product( $data ) {
    $data['color'] = 'red';

    return $data;
}

我们还为产品 schema 的 offer 部分提供了一个更具体的过滤器:wpseo_schema_offer,更多信息请参阅 Offer Schema 片段

要对我们的 Schema 输出进行更多修改,请参阅 Yoast SEO Schema API