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 ;) )

Related Posts

Related Posts

No related posts.

43 Responses

Mar 16 2009 12:42

Thanks for the recipe, I’ve already used your recipe for a Twitter Button. Well thanks for all the recipes actually, very useful website !!

Anyway, do you have the recipe to add a “send to friend” button, to send the current article or the current page to a friend by mail ? I don’t wanna use these social bookmarks plugins that add dozens of buttons to send to facebook, twitter, digg, mail, etc.

Thanks again !

Mar 16 2009 16:49

Good tips, thanks.

Mar 16 2009 17:58

Nice tip. It would be nice to make a tutorial for other social bookmarking sites too.

Mar 16 2009 21:30

Simple, I find these types of things by looking at the source code of sites that already use it.

Mar 17 2009 20:25

Couldn’t get any easier, could it?

Yan

Apr 05 2009 08:40

Thanks again, another great tip

Apr 14 2009 04:30

Thanks.. this is awesome.. I just used it :)

Apr 18 2009 18:37

Simple and useful, thanks.

May 20 2009 14:17

Man, your site rocks! Another bit of extremly useful code, thanx again!!!

May 26 2009 09:49

Thnaks a lot helpd me as a base for my b2evolution Blog to make something similar .Not that good ,(permalink variables )but working for now
Greets

Jun 14 2009 15:40

hi, thx for the code, but it just doesn’t seem to work on my site.
i’m using a theme named ‘gold pot theme’, and it has an embedded ’share on facebook’ icon on its top navigation. it has a user-friendly customization field to tweak the facebook link like this:

Your Facebook profile ID: —————-
(You can find your profile ID by clicking on your profile, you will see an ID number there. Just copy that ID and paste it here!)

i’m entering my facebook id in the profile field: widiantozhu, since i’ve reserved my own facebook username (www.facebook.com/widiantozhu) and can no longer retrieve my facebook profile (number) id. but the problem is, everytime i click on the fb link, it will take me straight to my facebook account page instead of sharing it.

so i open the header.php and replace the with the link code you’ve provided, still nothing changes.

so, can anyone help me with the customization?

thanks a lot guys :)

Jun 14 2009 15:55

sorry to forgot to tell you one thing: this theme (gold pot theme) doesn’t have single.php. that’s why i ask. thx :)

Jun 20 2009 14:05

Thanks for the tip!

Jun 30 2009 20:27

i am new user of wordpress blog and i really do not have idea how to do it but i want to creat “share on facebook”button.i read your suggestion but i even do not know how to go the place where i can past the code u have told.so could u please tell me briefly how to do it?if you could do so it would be usefull for lot of new user.

Jul 23 2009 18:31

Thank you, I have implemented this, but added a small gif-picture also

Jul 23 2009 19:25

I even could not enter to single php and i dnt know what is single php so how can i copy and paste this at the single php…could you please teach me how to go to single php and paste the above code?

Aug 16 2009 22:02

I am not very savvy at this stuff. Does the Rounded theme have this option? Where do I find the single.php file? :)

Aug 24 2009 05:44

Thanks for this tip. When I click on the single php file, I click “edit code” and paste your code in the middle of the code already there. I’m assuming this is “in the loop”? When I refresh my site, there is no change. Am I pasting your code in the wrong place?

Thanks,
Kristy

Sep 16 2009 23:45

Just what I needed for my blog, thanks

Oct 26 2009 01:23

As several other people have asked (and received no answer), where is this “single php” file? I can find no such entity on my site.

Oct 26 2009 09:00

@Zak Martin : The single.php file is the file used to display blog posts individually. It can be found on your theme directory.

Oct 28 2009 11:01

Great and simple ! Thanks a lot ! Sylvie

Nov 18 2009 18:48

ah so simple, I didn’t know that

Nov 27 2009 22:13

” The single.php file is the file used to display blog posts individually. It can be found on your theme directory”

I click on Themes and there is no single file listed there. I need a ‘for dummies’ version pls.

Dec 02 2009 23:12

Thank you for this great code! I’ve customized the link to facebook, it looks GREAT !!! I will also mesure the number of people clicking on it using Analytics. Thank you again !!

Jan 05 2010 02:55

“@Z Martin : The single.php file is the file used to display blog posts individually. It can be found on your theme directory.”

You might as well be speaking Martian. As the guy above said, can we please have the non-techie version?
When I click on the “theme” link at the foot of my individual blog page, I go to a page for RSS feeds. I can’t find any mention of a single-php file, or any way to upload snippets of script. Can you please give us simplified, step-by-step instructions, without assumimg prior knowledge?
Thanks

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required