Post Pic

How to: Add a “Share on facebook” link to your WordPress blog

As you know it, facebook is a very popular website, which allow you to share webpages you like with your friends. In order to promote your blog and gain some more traffic, you should definitely add a “Share on Facebook” link to your blog.

Simply paste the following code on your single.php file, 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>

That's all. Your readers are now able to send your blog post on Facebook and share it with their friends!
(PS: I'm not on facebook, so don't ask ;) )

24 Responses

Sep 11 2011 03:30

Wondering if you knew how to get the Like on FB (or “Share This Blog”) when one doesn’t have a custom blog theme? I don’t have a place to put plug-in info (I’m at wordpress).

Thanks!

Sep 25 2011 11:18

when i add the code to single.php it only shows the like button on the new posts and not the old ones. can i add it to the old ones too?

Nov 29 2011 06:34

dont forgot the head application in your theme folder

Dec 29 2011 23:25

could you share the the code for placing it in the functions.php file to prevent future upgrade overwrites? Thanks!!

Jan 11 2012 17:01

Minor amend to this would be to make the link contain & not & to help with HTML validation :)

Jan 14 2012 15:55

It would be nice to know where single.php is. I’ve looked through all the directories and can’t find it.

Jan 27 2012 21:08

Donald, to find single.php go to “yourblog”/wp-content/themes/”anyThemeThatYouChoose

Mar 11 2012 19:32

Where would that single.php file be located? I am new at this and cannot find it.

Mar 11 2012 19:36

Actully, I don’t even know where to look for these directories you are talking about. I put the link in my browser that you stated above and that didn’t work. Please tell this challenged individual exactly what you mean in simple terms.

Mar 16 2012 16:33

http://en.forums.wordpress.com/topic/its-possible-facebook-share-and-like-buttonsat-the-same-time?replies=90

This helped me…the button doesn’t look quite the way I want, but now I know where to put the info to make it work.

Hope it helps you.

Jun 04 2012 17:03

This was helpful! I´ve taken it a little further though:

http://pastebin.com/egcUBfEz

;-)

Jun 14 2012 16:16

I copied the code at the top of the page and it worked great but the Sh is not centered. What do I add to the code that would center it like the others.

Jul 11 2012 19:19

I got a question.
i’ve used the code successfully, but i want to open a new popup window once the link is clicked.

any help

Aug 09 2012 09:20

I dont think, you will get any solution for this after one year :)

Aug 19 2012 16:12

maybe someone could post a script of his work so you can copy what he or she did?

Aug 23 2012 16:14

Excellent blog post. I definitely appreciate this site. Keep writing!

Sep 19 2012 06:32

I like this script a lot. One question though, it doesn’t seem to pull images when clicked. Any ideas how to add that as well?

Oct 09 2012 10:58

Well, it dosnt work at IE, but who really cares about that?

Dec 07 2012 19:32

Well It works, but the og:description and og: title are pulled from the website.

I wonder if it is possible to pull the description from individual posts…

Dec 27 2012 10:47

You can put the code on the footer php or even on the widget area.

Jan 19 2013 15:41

i past in in function.php …my site crashed …careful

Feb 17 2013 18:20

I do believe all the ideas you have introduced on your post.
They are very convincing and will certainly work. Still, the posts are very short for starters.

Could you please extend them a little from next
time? Thanks for the post.

Mar 23 2013 22:05

Hello there! This is my first comment here so I just
wanted to give a quick shout out and tell you I really enjoy reading
your blog posts. Can you recommend any other blogs/websites/forums that go over the same subjects?
Thank you!

Mar 30 2013 19:45

Check out the latest study on molecular nutrition and food research scientists that show that compounds in mate tea induce death in colon cancer cells.
The cold version of the tea is popularly called Terere.
The best time is generally the first hour after breakfast.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox