Add Job Title and Expertise to Yoast's Person Schema
Adds a job title and "knows about" topics from each author's profile to the Person pieces Yoast SEO outputs, which supports E-E-A-T signals.
Opens WPIDE on
Code
add_filter( 'user_contactmethods', function ( $methods ) {
$methods['wpide_job_title'] = 'Job title (schema)';
$methods['wpide_knows_about'] = 'Topics of expertise, comma separated (schema)';
return $methods;
} );
add_filter( 'wpseo_schema_person', function ( $data ) {
if ( ! is_array( $data ) || empty( $data['@id'] ) ) {
return $data;
}
// Find the user this Person piece describes: the post author or the author archive.
$user_id = 0;
if ( is_author() ) {
$user_id = get_queried_object_id();
} elseif ( is_singular() ) {
$user_id = (int) get_post_field( 'post_author', get_queried_object_id() );
}
if ( ! $user_id ) {
return $data;
}
$job = get_the_author_meta( 'wpide_job_title', $user_id );
$knows = array_filter( array_map( 'trim', explode( ',', (string) get_the_author_meta( 'wpide_knows_about', $user_id ) ) ) );
if ( $job ) {
$data['jobTitle'] = $job;
}
if ( $knows ) {
$data['knowsAbout'] = array_values( $knows );
}
return $data;
} );
Notes
Adds two fields to user profiles. Separate topics with commas.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.