How to Add Facebook Authorship in WordPress

Facebook provides plenty of services to let websites be more engaging throughout the social network, such as using the Comment, Likebox, the eminent Like button, and more recently it has improved the Author Tagging feature. The Author Tag, when provided, allows Facebook to tag the shared article with the author’s Facebook profile.

Note that the Author Tag is not new, it is just been improved to display the author’s name along with a linkback to the profile of the article, if provided.

This is a good opportunity for news sites or multiple-authored blogs to increase their journalists, writers, and bloggers credibility on Facebook. Herein, we are going to see how to integrate the Author Tagging into your WordPress site.

1. Theme Coding

To begin with, we need to an extra input field in the Profile Edit screen to allow the author to enter their Facebook profile URL.

Open the functions.php of your theme, and put the following codes in.

function facebook_profile_url($profile_fields) {
	$profile_fields['facebook_url'] = 'Facebook URL';
	return $profile_fields;
add_filter('user_contactmethods', 'facebook_profile_url');

This code adds an extra field under the “Contact Info”. Enter the Facebook URL, for example, and save.

Now, we need to output the URL in the head of the theme. To do so, add the following code in the functions.php.

function facebook_author_tag() {
	if ( is_single() ) {
		global $post;
		$author = (int) $post->post_author;
		$facebook_url = get_the_author_meta( 'facebook_url', $author );
		if ( ! empty( $facebook_url ) ) {
			echo '<meta property="article:author" content="'. $facebook_url .'" />';
add_action( 'wp_head', 'facebook_author_tag', 8 );

This code retrieves the URL, and output it in the article:author meta tag as per the Facebook Open Graph specification. We wrap the code within a conditional function, is_single(), to ensure that the meta tag would only be generated in the single post or the article.

Furthermore, the code also verifies if the URL is present, if it isn’t, we won’t output the meta tag. Refresh the article page and you should find the tag in the head tag.

2. Using a Plugin

If coding isn’t up your alley, you can easily do so with a plugin instead. We can use Yoast SEO. It is a good plugin that helps with optimization for your website both in search engines and in social sites like Facebook. Once it has been installed, you should find a new input “Facebook Profile URL” added in your profile edit.

Enter your Facebook URL. Save to update the profile, and you are all set. You do not need to modify your theme to add the tag, as the plugin has done it all for you.

That’s it, whichever way you opted, you now have the article tagged with the author. Now, if you have multiple authors contributing to your site, make an announcement asking them to input their Facebook URL. And make sure that the URL is correctly pointing to the right profile.

Hope you find this tip useful!