Post SEO Wordpress

How to remove / change the person / author schema in the Yoast SEO plugin for WordPress

Today I'm going to talk you about how you can remove / change the person / author schema in the Yoast SEO plugin for WordPress. I think this is going to be a problem for a lot of people using version 11+ of the Yoast SEO plugin for WordPress.

In versions 11+ Yoast have added a ton of new schema markup, which is great, but I had a problem for a website that was configured in Yoast SEO as an organisation (you can configure your site as either representing a person or an organisation). The issue was, that like a lot of WordPress sites, they were using one login to post their blog articles. This user / login was not actually a person and this was the root of the issue because Yoast SEO version 11+ adds the person and author schema markup to all WordPress posts (articles in the schema). So you end up with something like this:

{"@type":"Article",
"@id":"http://domain.com/post-title/#article",
"isPartOf":{"@id":"http://domain.com/post-title/#webpage"},
"author":{"@id":"http://domain.com/blog/author/shared-login-name/#author",
"name":"Shared Login Name"},
"publisher":{"@id":"http://domain.com/#organization"},
"headline":"The Post Title",
"datePublished":"2018-11-15T08:20:49+00:00",
"dateModified":"2019-02-14T14:24:15+00:00",
"commentCount":0,
"mainEntityOfPage":"http://domain.com/post-title/#webpage",
"image":{"@id":"http://domain.com/post-title/#primaryimage"},
"keywords":"blah blah",
"articleSection":"The Category"
},
{"@type":"Person",
"@id":"http://domain.com/blog/author/shared-login-name/#author",
"name":"Shared Login Name",
"image":{"@type":"ImageObject",
"@id":"http://domain.com/#personlogo",
"url":"http://2.gravatar.com/avatar/xxx",
"caption":"Shared Login Name"},
"sameAs":[]}]
}

Essentially you end up with Person and Author schema markup which references your shared login which actually represents nothing and no one. So how do you remove / change the person / author schema? This took me a while to work out, but essentially you can use the Yoast SEO plugin's API.

Firstly, you can simply remove the Person schema by adding this to your theme's functions.php file:

//disable Yoast SEO @Person schema on posts
add_filter( 'wpseo_schema_needs_author', '__return_false' );

Now your schema output for the article (posts) will not include the Person type:

{"@type":"Article",
"@id":"http://domain.com/post-title/#article",
"isPartOf":{"@id":"http://domain.com/post-title/#webpage"},
"author":{"@id":"http://domain.com/blog/author/shared-login-name/#author",
"name":"Shared Login Name"},
"publisher":{"@id":"http://domain.com/#organization"},
"headline":"The Post Title",
"datePublished":"2018-11-15T08:20:49+00:00",
"dateModified":"2019-02-14T14:24:15+00:00",
"commentCount":0,
"mainEntityOfPage":"http://domain.com/post-title/#webpage",
"image":{"@id":"http://domain.com/post-title/#primaryimage"},
"keywords":"blah blah",
"articleSection":"The Category"
}

However, within the article schema you still have the author element which is outputting your shared login non-person. My solution was again to use the Yoast SEO plugin's API, but this time to change the output of this author element as follows (add this to your functions.php file):

//change Yoast SEO article schema author to the organization
add_filter( 'wpseo_schema_article', 'change_article_author' );

/**
 * Change @type of Article Schema data.
 *
 * @param array $data Schema.org Article data array.
 *
 * @return array $data Schema.org Article data array.
 */
function change_article_author( $data ) {
  $data['author'] = 'Your Organisation Name Here';
  return $data;
}

This changes the author element to the name of your organisation i.e. now the organisation is the author and we've removed the author url:

{"@type":"Article",
"@id":"http://domain.com/post-title/#article",
"isPartOf":{"@id":"http://domain.com/post-title/#webpage"},
"author":"Your Organisation Name Here",
"publisher":{"@id":"http://domain.com/#organization"},
"headline":"The Post Title",
"datePublished":"2018-11-15T08:20:49+00:00",
"dateModified":"2019-02-14T14:24:15+00:00",
"commentCount":0,
"mainEntityOfPage":"http://domain.com/post-title/#webpage",
"image":{"@id":"http://domain.com/post-title/#primaryimage"},
"keywords":"blah blah",
"articleSection":"The Category"
}

And there you have it, hope this helps someone out, tweet me @jodyvanv if it does. Here's the full snippet to add to your WordPress theme's functions.php file:

//disable Yoast SEO @Person schema on posts
add_filter( 'wpseo_schema_needs_author', '__return_false' );

//change Yoast SEO article schema author to the organization
add_filter( 'wpseo_schema_article', 'change_article_author' );

/**
 * Change @type of Article Schema data.
 *
 * @param array $data Schema.org Article data array.
 *
 * @return array $data Schema.org Article data array.
 */
function change_article_author( $data ) {
  $data['author'] = 'Your Organisation Name Here';
  return $data;
}