Author Profile Structured Data
Adds ProfilePage JSON-LD to author archives, describing the author as a person with their name, bio, avatar and website.
Opens WPIDE on
Code
add_action( 'wp_head', function () {
if ( ! is_author() ) {
return;
}
$author = get_queried_object();
if ( ! $author instanceof WP_User ) {
return;
}
$person = array(
'@type' => 'Person',
'name' => $author->display_name,
'url' => get_author_posts_url( $author->ID ),
'image' => get_avatar_url( $author->ID, array( 'size' => 256 ) ),
);
if ( $author->description ) {
$person['description'] = wp_strip_all_tags( $author->description );
}
if ( $author->user_url ) {
$person['sameAs'] = array( $author->user_url );
}
$data = array(
'@context' => 'https://schema.org',
'@type' => 'ProfilePage',
'mainEntity' => $person,
);
echo '<script type="application/ld+json">' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG ) . "</script>\n";
} );
Notes
Author archives must be enabled for this to have any effect.
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.