, WordPress

Add Social Settings to Your WordPress Theme

WordPress offers user profiles with settings for social links; however, many social sites like Facebook and Google+ offer opportunities for your entire site or blog to have a presence within those networks. We were working on a client site this week where we wanted to make it easy for them to set and add their site’s social links, so we added additional options to their WordPress General Settings page.

Our first step was to update their Theme Functions (typically functions.php) and register each of the settings we wished to add:
// —————Add Settings to General Settings—————–
function social_settings_api_init() {
// Add the section to general settings so we can add our
// fields to it
add_settings_section('social_setting_section',
'Social sites on the web',
'social_setting_section_callback_function',
'general');

// Add the field with the names and function to use for our new
// settings, put it in our new section
add_settings_field('general_setting_facebook',
'Facebook Page',
'general_setting_facebook_callback_function',
'general',
'social_setting_section');

// Register our setting so that $_POST handling is done for us and
// our callback function just has to echo the <input>
register_setting('general','general_setting_facebook');

add_settings_field('general_setting_twitter',
'Twitter Account',
'general_setting_twitter_callback_function',
'general',
'social_setting_section');
register_setting('general','general_setting_twitter');

add_settings_field('general_setting_googleplus',
'Google Plus Page',
'general_setting_googleplus_callback_function',
'general',
'social_setting_section');
register_setting('general','general_setting_googleplus');

add_settings_field('general_setting_youtube',
'YouTube Page',
'general_setting_youtube_callback_function',
'general',
'social_setting_section');
register_setting('general','general_setting_youtube');

add_settings_field('general_setting_linkedin',
'LinkedIn Page',
'general_setting_linkedin_callback_function',
'general',
'social_setting_section');
register_setting('general','general_setting_linkedin');
}
add_action('admin_init', 'social_settings_api_init');

Our next step was to add the actual fields within the General Settings page that would save the information within them:
// —————-Settings section callback function———————-
function social_setting_section_callback_function() {
echo '<p>This section is where you can save the social sites where readers can find you on the Internet.</p>';
}
function general_setting_facebook_callback_function() {
echo '<input name="general_setting_facebook" id="general_setting_facebook" type="text" value="'. get_option('general_setting_facebook') .'" />';
}
function general_setting_twitter_callback_function() {
echo '<input name="general_setting_twitter" id="general_setting_twitter" type="text" value="'. get_option('general_setting_twitter') .'" />';
}
function general_setting_googleplus_callback_function() {
echo '<input name="general_setting_googleplus" id="general_setting_googleplus" type="text" value="'. get_option('general_setting_googleplus') .'" />';
}
function general_setting_youtube_callback_function() {
echo '<input name="general_setting_youtube" id="general_setting_youtube" type="text" value="'. get_option('general_setting_youtube') .'" />';
}
function general_setting_linkedin_callback_function() {
echo '<input name="general_setting_linkedin" id="general_setting_linkedin" type="text" value="'. get_option('general_setting_linkedin') .'" />';
}

Now, anytime the client wishes to update their social page settings, they can just update the settings fields within their WordPress General Settings. Within the theme, we simply recall the setting wherever needed (in this client’s case, it was a social media navigation bar in the heading of their site):

<?php echo get_option('general_setting_facebook'); >

2 Comments

  1. 1
    • 2

      Yes, sure could. I just think it needs some additional bells and whistles first… like automatically publishing the G+ publisher link in the header, the open graph meta data for Facebook, etc.  Just doing this didn’t seem cool enough!

Leave a Reply