Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.