How to Easily Add Facebook Authorship in WordPress
Facebook offers various tools to enhance engagement across its network, including the Comment, Likebox, and the popular Like button. Additionally, it has recently enhanced its Author Tagging feature. With an Author Tag, Facebook can link shared articles directly to the author’s Facebook profile.
Although not a new feature, the Author Tag now shows the author’s name and provides a link back to their profile, enhancing visibility.
This is particularly beneficial for news sites or blogs with multiple authors, as it helps to boost the credibility of journalists, writers, and bloggers on Facebook. Let’s explore how to integrate Author Tagging into your WordPress site.
Step 1: Theme Coding
Firstly, add an extra input field in the Profile Edit screen for authors to enter their Facebook profile URL.
Open the functions.php file of your theme and insert the following code:
function facebook_profile_url($profile_fields) { $profile_fields['facebook_url'] = 'Facebook URL'; return $profile_fields; } add_filter('user_contactmethods', 'facebook_profile_url');
This code snippet adds a new field under “Contact Info”. Simply enter the Facebook URL, for example, https://www.facebook.com/zuck
, and save the changes.
Next, we need to output the URL in the head
section of the theme. Add this code to the functions.php file:
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 Facebook URL and inserts it into the article:author
meta tag, adhering to Facebook’s Open Graph specifications. It ensures the tag is only generated on individual post pages and checks if the URL is provided before outputting the meta tag. Refresh your post page to see the new tag in the head
section.
Step 2: Using a Plugin
If manual coding isn’t your thing, a plugin can handle everything for you. Yoast SEO is a great choice for optimizing your site for search engines and social networks like Facebook. After installation, you’ll find a new “Facebook Profile URL” field in your profile editor.
Simply enter your Facebook URL, save the changes, and you’re all set. There’s no need to modify your theme – the plugin takes care of it for you.
Whichever method you choose, your articles will now be tagged with the author’s name. If your site has multiple contributors, encourage them to add their Facebook URLs. This ensures accurate linking to their profiles.
We hope you find this guide helpful!
Note: This post was first published on the Aug 25, 2015.