I didn’t create these snippets, but I was surprised not to see them documented together since they rely on each other. The first function adds custom social fields to a WordPress user profile, and the second ensures those fields are included in Yoast SEO’s Person schema output. In this example, the fields cover IMDB, GitHub, and WordPress profiles, but the code can easily be adapted for other platforms such as TikTok, Bluesky, or any other site with user profiles.
//Add additional social links to user profile
add_filter( 'user_contactmethods', 'modify_user_contact_methods' );
function modify_user_contact_methods( $methods ) {
// Add user contact methods
$methods['imdb'] = __( 'IMDB page URL', 'textdomain');
$methods['github'] = __( 'GitHub profile URL', 'textdomain');
$methods['wordpress'] = __( 'WordPress profile URL', 'textdomain');
return $methods;
}
add_filter( 'wpseo_schema_person_social_profiles', 'yoast_add_social_profiles' );
/**
* Adds social profiles to our sameAs array.
*
* @param array $profiles Social profiles.
*
* @return array Social profiles.
*/
function yoast_add_social_profiles( $profiles ) {
array_push( $profiles, 'imdb', 'github', 'wordpress' );
return $profiles;
}