Skip to main content
Menu

How to Use Social Links from SEOPress & Yoast SEO in WordPress Themes

June 9th, 2020

If you build WordPress themes, it’s a common need to pull a set of client’s social media links to place somewhere on the site, whether that’s the header or footer or a sidebar.

Most WordPress SEO plugins like SEOPress and Yoast SEO collect this data for the client for Schema purposes and include a tab to input this data. For SEOPress, it’s located under SEO > Social Networks. For Yoast, it’s under SEO > Social.

A screenshot of SEOPress' social networks page
A screenshot of the social network settings page of SEOPress

Previously, I had made life more difficult for myself and frequently created an options panel for a client with fields to populate social media links then pulled these into the theme. Finally, it dawned on me that surely there is a way to prevent this duplicate content entry and I can just extract the social links from these plugin pages. And there is!

If you use SEOPress, you can pull the data into a variable with:

<?php $social_data = get_option( 'seopress_social_option_name' ); ?>

If you use Yoast SEO, you can pull the data into a variable with:

<?php $social_data = get_option( 'wpseo_social' ); ?>

What you can do from that point is spit out everything in the array to figure out the keys for what you’re wanting to grab with:

<?php var_dump($social_data); ?>

It may end up being something like:

<?php echo $social_data['seopress_social_accounts_facebook']; ?>

To pull the Facebook link and similar.

That’s all there is to it! No more duplicate content fields and data entry for social media link management.

MORE: WordPress Development, WordPress Tutorials

Related Articles

Copy link
Powered by Social Snap