Create a “Share on Facebook” Button for Your WordPress Blog

A few weeks ago I posted the article Create a “Send to Twitter” button for your WordPress blog, in which you can create a button that will share what you are reading with your followers.

This week I will show you how you can add a “Share on Facebook” button in your WordPress blog to bring in more visitors. This is very simple, just like the Twitter button tutorial.

Open your single post file (single.php) file from your theme directory and insert the following code within the loop:

<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>
&t=< ?php the_title(); ?>" target="_blank">Share on Facebook</a>

To make things more interesting, you can use getTinyUrl() function to send a short URL to Facebook:

< ?php $turl = getTinyUrl(get_permalink($post->ID)); ?>
<a href="http://www.facebook.com/sharer.php?u=<?php echo $turl;?>&t=
< ?php the_title(); ?>" target="_blank">Share on Facebook</a>

That’s it! Now your readers will able to share your posts in their Facebook. This is a great way to boost your site’s traffic!

Source: WPRecipes

Back to top ↑

1 comment so far »

  1. Pete wrote on June 21, 2011 @ 7:44 am

    Thanks for the great tip!

Comment RSS · TrackBack URI


Back to top ↑

Leave a comment

Name: (Required)

E-mail: (Required)

Website:

Comment:

Spam protection:
What is the sum of 1 + 6 ?