Nov 5, 2010

There are a large number of WordPress plugins available to add social networking tools to your WordPress installation. In fact, it is difficult to know where to begin when faced with page after page of plugins that support Twitter, Facebook, and all the rest.

For my blog, I decided I wanted small, discrete share buttons at the end of all posts and some, but not all, pages. I also wanted a Tweet feed to show my latest Tweets. Finally, I wanted a Tweet counter for each page so I could track whether people were using the sharing tools and a “follow me” link so people could jump to my Tweet page.

I ended up using two plugins to handle these tasks.

For the Tweet feed in the sidebar, I wanted a simple widget so I found the aptly named  Simple Twitter Widget by Matthias Siegel. This plugin adds a widget that you can drag into your sidebar and select a few simple options. This plugin will cache the twitter feed in a local file and is refreshed on a configurable interval. This is better than using the widget code provided directly by Twitter which refreshes the code on every page load.

I used a Twitter-supplied “follow me” button, adding the code as a text widget with a bit more formatting than the default provided by Twitter.

In order to add share buttons on posts and pages I tried several different plugins before I settled on WP Socializer by Aakash Chakravarthy. This provided a configurable size and format for buttons, and also provided an interface so that I could program my template to select some, but not all, pages to include social buttons.

The setup of the buttons on posts was simple and intuitive. I selected a number of small share buttons on the “Social Buttons” page in the settings. Then I used a custom button for Twitter because I didn’t like the choices provided by the plugin – the default Tweet button that Twitter provides is nicer. So I set up custom-1 on the “Custom” tab with the code provided by Twitter. I used template 1 in the Placement settings to add the buttons to all posts. My template 1 code looks like this:
<h3>Share This</h3>
{social-bts-16px}
{custom-1}
<br />

The next step was to add the buttons to selected pages only. I did this by adding a new custom field named “share-this” to my selected pages. I set the value to “true”. Then I added this code to my page template in the position where the buttons should appear:


if(function_exists('wp_socializer')){
$mykey_values = get_post_custom_values('share-this');
if (is_array($mykey_values)) {
foreach ( $mykey_values as $key => $value ) {
if ($value == 'true') {
echo wp_socializer('social-bts-16px');
echo wp_socializer('custom-1');
}
}
}
}

With this code, every page that contains the custom field “share-this” set to “true” will display the small buttons and custom button.

Share This

  • Twitter
  • Facebook
  • Digg
  • Google Buzz
  • StumbleUpon
  • LinkedIn

One Response to “Adding Twitter to your WordPress Blog”

  1. soapmaker says:

    very nice. I really like the way you chose to setup the socialize plugin.

Leave a Reply