Skip to content

Instantly share code, notes, and snippets.

@amboutwe
Last active November 1, 2023 22:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amboutwe/36a08f9d369860aec99500726065bd3f to your computer and use it in GitHub Desktop.
Save amboutwe/36a08f9d369860aec99500726065bd3f to your computer and use it in GitHub Desktop.
Remove Yoast SEO Social Profiles From All Users
/* Remove Yoast SEO Social Profiles From All Users
* Credit: Yoast Developers
* Last Tested: Nov 01 2023 using Yoast SEO 21.5 on WordPress 6.3.2
*********
* Use this code to hide the fields shown under Admin > Users > Edit user
* Previously entered profiles will be included in schema
* To limit or remove user schema, use 'wpseo_schema_person_social_profiles' filter
* Link: https://developer.yoast.com/features/schema/pieces/person/#social-profiles
*/
add_filter('user_contactmethods', 'yoast_seo_admin_user_remove_social', 99);
function yoast_seo_admin_user_remove_social ( $contactmethods ) {
unset( $contactmethods['facebook'] );
unset( $contactmethods['instagram'] );
unset( $contactmethods['linkedin'] );
unset( $contactmethods['myspace'] );
unset( $contactmethods['pinterest'] );
unset( $contactmethods['soundcloud'] );
unset( $contactmethods['tumblr'] );
unset( $contactmethods['twitter'] );
unset( $contactmethods['youtube'] );
unset( $contactmethods['wikipedia'] );
unset( $contactmethods['mastodon'] ); // Premium feature
//Do not remove the lines below
return $contactmethods;
}
@filipecsweb
Copy link

filipecsweb commented Mar 1, 2018

I may have a better one for you:
<?php remove_filter( 'user_contactmethods', array( ! empty( $GLOBALS['wpseo_admin'] ) ? $GLOBALS['wpseo_admin'] : '', 'update_contactmethods' ), 10 );

Also, you might want to talk to the Yoast developers about adding an option in admin to disable this feature.

@bwalker541
Copy link

Under WordPress 5.2.2 and Yoast SEO 11.9, I had to add the priority to the filter. Otherwise the user contacts array hadn't been populated by Yoast Plugin yet.

add_filter('user_contactmethods', 'yoast_seo_admin_user_remove_social', 99);

Also, I have to +1 that this should be an option in Yoast Admin, especially for subscribers.

@amboutwe
Copy link
Author

@fearlex This is not the proper place to request changes for Yoast SEO features. Instead, please create a request here: https://github.com/Yoast/wordpress-seo/

@fearlex
Copy link

fearlex commented Jan 25, 2021

@amboutwe Not trying to request anything, just letting anyone who reach this gist trying to fix the same issue I was trying to fix that is still not fixed in 2021 and there is no setting for it. I removed my comment.

@soulshakepower
Copy link

@bwalker541 Thank you for the priority tweak, can you guys from Yoast include this in your code on top? Otherwise not working at all. Thanks

@amboutwe
Copy link
Author

@soulshakepower Thanks for the feedback. I updated the code snippet with the priority option.

@soulshakepower
Copy link

WoW @amboutwe thanks for light-fast update :) And cheers to all the team for your great SEO solutions!

@damienvancouver
Copy link

By the time I found this thread (Dec 2021) there were a bunch more still! It's easiest to just make your filter function return an empty array, instead of removing one at a time and then having Yoast just add more of the darned things. Here is my filter function which just gets rid of all of them, present and future.

	/**
	 * Remove annoying Yoast social fields from user profile forms.
	 * @see https://gist.github.com/amboutwe/36a08f9d369860aec99500726065bd3f
	 */
	public function yoast_seo_admin_user_remove_social($contactmethods)
	{
		// we want none of them now or in the future!  
                // return an empty array rather than remove one by one:
		return array();
	}

@factoryofit
Copy link

How to remove Mastodon field?

unset( $contactmethods['mastodon'] ); - not works for me ((

@amboutwe
Copy link
Author

amboutwe commented Nov 1, 2023

@factoryofit I tested and updated the code snippet to remove the Mastodon field. Please note that the fields are only removed from the User Profile screen under Admin > Users > Edit user.

If the issue remains for your site, this is not the proper place to request support. Please check out our extensive help section or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment