Yoast SEO 开发者文档

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


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

描述 WebSite 上的单个页面。作为子页面元素(如 Article)的容器。

充当页面内容到父级 WebSite(进而到 Organization)的连接器。

如果满足所需条件,可转换为更具体的类型(如 FAQPage)。

触发器

应在所有公开页面上输出,4xx5xx 系列错误页面/场景除外。

必需属性

有效的 WebPage 必须包含以下属性。

失败场景

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

可选属性

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

条件属性

仅在满足特定条件时才应输出的可选属性。

当页面为常规页面时(而非文章归档、用户资料等)

当页面被创作

当页面有评论,且页面包含有效文章时

当页面为主页时

转换

WebPage 类型可能在以下场景中发生转换。

分类索引

当查询返回文章循环时(例如分类归档、博客首页或其他分类索引),则应将 type 属性更改为 CollectionPage

个人资料页

当页面涉及特定用户时(例如:成员简介/作者归档):

常见问题页面

当页面包含常见问题时,应将 type 属性转换为包含 FAQPageWebPage 的数组(或按上文所述采用最具体的转换方式)。

搜索结果页面

在搜索结果页面上,应将 type 属性修改为 [CollectionPage, SearchResultsPage] 数组。

Examples

Minimum criteria

{{ "@context": "https://schema.org", "@graph": [ { "@type": "WebPage", "@id": "https://www.example.com/example-page/", "url": "https://www.example.com/example-page/", "name": "Example page name", "isPartOf": { "@id": "https://www.example.com/#/schema/WebSite/1" } } ] }}

Extended criteria

{{ "@context": "https://schema.org", "@graph": [ { "@type": "WebPage", "@id": "https://www.example.com/example-page/", "url": "https://www.example.com/example-page/", "name": "Example page name", "description": "Example page description", "keywords": ["cats","dogs","cake"], "isPartOf": { "@id": "https://www.example.com/#/schema/WebSite/1" }, "inLanguage": "en-US", "datePublished": "2019-07-10T08:08:40+00:00", "dateModified": "2019-07-10T08:43:03+00:00", "breadcrumb": { "@id": "https://www.example.com/#/schema/BreadcrumbList/abc123" }, "primaryImageOfPage": { "@id": "https://www.example.com/uploads/example-image.jpg" }, "image": [ { "@id": "https://www.example.com/uploads/example-image.jpg" }, { "@id": "https://www.example.com/uploads/example-image-2.jpg" } ], "video": [ { "@id": "https://www.example.com/#/schema/VideoObject/abc123" }, { "@id": "https://www.example.com/#/schema/VideoObject/def456" } ], "potentialAction": [ { "@type": "ReadAction", "target": [ "https://www.example.com/example-page/" ] } ] } ] }}

WordPress API:修改网页 Schema 输出 {#api}

要修改 Yoast SEO 输出的 Webpage Schema,你可以使用我们的 wpseo_schema_webpage 过滤器。以下是一个示例:

add_filter( 'wpseo_schema_webpage', 'example_change_webpage' );

/**
 * 修改 Webpage Schema 数据的 @type。
 *
 * @param array $data Schema.org Webpage 数据数组。
 *
 * @return array Schema.org Webpage 数据数组。
 */
function example_change_webpage( $data ) {
    if ( ! is_page( 'about' ) ) {
        return $data;
    }

    $data['@type'] = 'AboutPage';

    return $data;
}

为了方便起见,我们还有一个更具体的过滤器:wpseo_schema_webpage_type - 用于更改页面类型,因此可以用来使上述示例更加简化。

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