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


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

描述一个独立的个人。最常用于标识内容(例如 ArticleComment)的 author

在某些情况下,也可用于标识 WebSite(或其他内容)的 publisher

触发器

应在其他节点需要时作为图的顶级节点添加。例如,当 Articleauthor 时。

必需属性

一个有效的 Person 必须具有以下属性。

失败场景

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

如果未输出该节点,则任何原本会声明与该 Person 存在关系的实体(例如,作为 WebSitepublisher,或作为 Articleauthor)都应移除这些引用。

'Admin' 用户名

如果人员的 name 是 'admin' 或类似名称(或其本地化等效名称),则该 Person 应被标记为无效;我们绝不应将内容显示为由 'admin' 创作。

可选属性

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

条件属性

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

示例

Minimum criteria

{{ "@context": "https://schema.org", "@graph": [ { "@type": "Person", "@id": "https://www.example.com/#/schema/Person/abc123", "name": "Example person name" } ] }}

Extended criteria

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

WordPress API: Change Organization Schema output {#api}

To make changes to the Person schema that Yoast SEO outputs, you can use our wpseo_schema_person filter. Here is an example:

Change person output

add_filter( 'wpseo_schema_person', 'schema_change_person', 11, 2 );

/**
 * Changes the Yoast SEO Person schema.
 *
 * @param array             $data    The Schema Person data.
 * @param Meta_Tags_Context $context Context value object.
 *
 * @return array $data The Schema Person data.
 */
function schema_change_person( $data, $context ) {
    if ( isset( $data['worksFor'] ) && $data['worksFor'] === 'Yoast' ) {
        // Make references to "Yoast" actually reference the organization's graph piece.
        $data['worksFor'] = [ '@id' => $context->site_url . Schema_IDs::ORGANIZATION_HASH ];
    }

    return $data;
}

Change person being output

If you want to change the person being output in the schema, you can filter it like this:

add_filter( 'wpseo_schema_person_user_id', 'change_schema_person_id' );

/**
 * Changes the Yoast SEO Person schema.
 *
 * @param int $person_id The Schema Person ID.
 *
 * @return int $person_id The (possibly altered) person ID.
 */
function change_schema_person_id( $person_id ) {
    if ( $person_id === 12 ) {
        return 3; // Make sure this is a valid user ID.
    }
    return $person_id;
}

社交资料

若需调整 Person 输出中 sameAs 数组显示的社交资料,可通过 wpseo_schema_person_social_profiles 过滤器实现。我们在 yoast.com 网站中运用此方法,将成员的 GitHub、WordPress 资料及个人网站添加至 sameAs 输出:

add_filter( 'wpseo_schema_person_social_profiles', 'yoast_add_social_profiles' );

/**
 * 向 sameAs 数组添加社交资料。
 *
 * @param array $profiles 社交资料数组。
 *
 * @return array 更新后的社交资料数组。
 */
function yoast_add_social_profiles( $profiles ) {
    array_push( $profiles, 'github', 'personal', 'wordpress' );

    return $profiles;
}

如需对 Schema 输出进行更多调整,请参阅 Yoast SEO Schema API