How to actually get the Facebook "Like button" working on WordPress without a plugin

This is a post about how to code stuff in Word­Press. If you’re a reg­u­lar reader who doesn’t care about this stuff, just skip it. I won’t be offended.

I’ve spent so many hours frus­trated at this. I scoured the web for “how to” arti­cles, and none of them actu­ally solved my prob­lem… so here is the solu­tion I’ve sued to get the “like this” but­ton work­ing on all of my posts on my blog in both the index.php page and in my own sec­ond loop in the side­bar…

The iframe ver­sion of the like but­ton worked really eas­ily — it was only the FBML but­ton I had prob­lems with (which has cooler fea­tures). I couldn’t fig­ure out how to get the FBML Face­book Like option to work on Word­Press with­out using a plu­gin. I don’t like plu­g­ins (if I can code it myself).

Here are the steps I took that I think solved my prob­lem (I will try adding some things I removed back in to see if they break what I’ve done).

Step 1. Remove any “Face­book Share” plu­g­ins or code already in your posts. I read on one of the plu­g­ins that it might clash with pre­ex­ist­ing Face­book code.
Step 2. Set up your “appli­ca­tion” on Face­book.

In the set up options go to the “Con­nect”… make sure you put your URLs in the “con­nect” page.

I sus­pect, though I’m not sure, that you need to choose the FBML option on the Can­vas page.

Step 3. Now you need to put some code in your header.

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml">

And this…

<meta property="og:site_name" content="YOUR BLOG NAME"/>
<meta property="og:title" content="<?php the_title_attribute( '' ); ?>"/>
<meta property="og:type" content="blog"/>
<meta property="og:image" content="THE URL TO THE IMAGE YOU WANT PEOPLE TO SEE ON FACEBOOK"/>
<meta property="fb:app_id" content="THE APP ID NUMBER FROM FACEBOOK (SEE BELOW)"/>

For exam­ple:

<meta property="og:site_name" content="St. Eutychus"/>
<meta property="og:title" content="<?php the_title_attribute( '' ); ?>"/>
<meta property="og:type" content="blog"/>
<meta property="og:image" content="http://st-eutychus.com/wp-content/themes/whiteplus/images/headertitle.png"/>
<meta property="fb:app_id" content="116899985006841"/>

Step 4. Insert the SDK code. Go to your footer.php and stick this block of code in before the you close your body tag (</body>)... this is the JavaScript SDK thing that Face­book talks about here — it allows you (because it’s in your footer) to call the “like” func­tion from any page that uses your footer. Make sure you put your app ID in the spot that says YOUR APP ID.

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: 'YOUR APP ID',
xfbml: true
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>

Step 5. Insert the Like But­ton Code. Facebook’s default “like but­ton” code won’t help you much if you want the address for indi­vid­ual posts to be sent through to your pro­file (and hope­fully those of your friends when they like what you’ve writ­ten. You need to change the URL option to call the post’s perma­link. Face­book will gen­er­ate you a block of code that will give you options like hav­ing your friends pho­tos appear when they like your post and stuff. I don’t want that. Put this where you want the like but­ton to appear. Here’s the code I used:

<fb:like width="340" height="30" layout="standard" show_faces="false" href="<?php the_permalink() ?>" colorscheme="default"></fb:like>

There may be some­thing to fac­tor in depend­ing on how your link struc­ture works — some other posts I read had a cou­ple of extra options around the perma­link)… they use some­thing like this: <?php echo urlencode(get_permalink($post->ID)); ?>

Cool stuff that you notice after doing a bit of Hebrew

Melchizedek (Gen­e­sis 14) is a cool king of Salem (Jerusalem) who blesses Abra­ham. His name, in Hebrew, means either “king of right­eous­ness” or “right­eous­ness is my king”.

Adoni-zedek (Joshua 10), is also the king of Jerusalem, who sum­mons an army of other kings to fight Israel. His name, in Hebrew, means “lord of right­eous­ness” or “right­eous­ness is my lord”…

Bit of a con­trast there…

There are no comments

Thursday, 29 April 2010, 17:10 | Category : Christianity
Tags : , , ,

Mario, you're toast.

Lit­er­ally. Here’s Mario ren­dered in bread toasted to var­i­ous degrees.

There are no comments

Thursday, 29 April 2010, 15:57 | Category : Curiosities
Tags : , , , ,

How to play Scissors, Paper, Rock against yourself

Just build this glove. Stick it on your hand. And Bob, as they say, is your uncle. The glove will learn how you play, and tel you what it thinks will beat you.

Swiss Army Axe*

For when a knife just won’t cut it

*Not really Swiss.

There are no comments

Thursday, 29 April 2010, 15:01 | Category : Curiosities
Tags : , , ,

Some changes

Well, by pretty pop­u­lar demand I have killed IntenseDe­bate. It’s back to no-frills com­ment­ing. Hope­fully that brings more of you out of the woodwork.

Face­book is try­ing to take over the inter­net — they announced some new toys for web devel­op­ers and blog­gers last week — I’ve included one (though haven’t quite got it work­ing yet — it should be fixed by the time you read this though…) that allows you to “like” a post both here and on Face­book with the click of a button.

I’ve also finally (and I’m pretty ecsta­tic about this one) man­aged to rewrite the code of my blog so that if you go to page 2 you don’t get page 1’s “Curiosi­ties” you get the next ten. That was really annoy­ing me.

If you think this post is largely point­less be sure to check out the tags (on the site) and you’ll see why I’ve posted it.

You know what's sad...

Stay­ing awake until 2am writ­ing web­site code try­ing to fix a lit­tle bug that nobody will notice anyway.

Sad­der still is post­ing to tell you all about it (and to clear my cache so that the changes will happen).

One Comment

Thursday, 29 April 2010, 1:58 | Category : Consciousness
Tags : , , , ,

Font of font knowledge

A font flow chart for every occa­sion — though it doesn’t include Hel­vetica. Sad­face. Click to make big­ger.

Via Life­hacker.

Update — as Gav points out, Hel­vetica is there. I just missed it.

YouTube Tuesday (almost): Balloon alien robot

Opti­mus Prime in bal­loon sculp­ture great­ness. Need I say more…

I hooked one

Long time read­ers will be famil­iar with my scam­bait­ing efforts from last year. I’ve been try­ing to get a photo of a Niger­ian Scam­mer hold­ing a bible verse. I got one. Finally. Not the John 3:16 ref­er­ence I was after, but I’m work­ing on that. Meet my friend Kenny. That’s what I call him.

Stay tuned for the story — I don’t want to blow it yet, I’m still hop­ing for that elu­sive John 3:16 poster. I’m pretty sure other scam­mers have googled them­selves and ended my game because of what they found.

Here’s his favourite Bible passage:

1Then I saw a new heaven and a new earth, for the first heaven and the first earth had passed away, and the sea was no more. 2And I saw the holy city, new Jerusalem, com­ing down out of heaven from God, pre­pared as a bride adorned for her hus­band. 3And I heard a loud voice from the throne say­ing, “Behold, the dwelling place of God is with man. He will dwell with them, and they will be his peo­ple, and God him­self will be with them as their God. 4 He will wipe away every tear from their eyes, and death shall be no more, nei­ther shall there be mourn­ing, nor cry­ing, nor pain any­more, for the for­mer things have passed away.”

5And he who was seated on the throne said, “Behold, I am mak­ing all things new.” Also he said, “Write this down, for these words are trust­wor­thy and true.”

One Comment

Wednesday, 28 April 2010, 22:12 | Category : Consciousness
Tags : , ,

Recent Comments

Pete Kutuzov (Kutz) : To clarify, that 'bollocks' was directed entirely at the analyst, not our good blogger here.
Read more...

Pete Kutuzov (Kutz) : Bollocks. She doesn't know what she's talking about. Early Ozzie is fantastic. Who gives a toss about whether he stands up to the canons of classical vocal technique? He's not trying to! He just
Read more...

Pete Kutuzov (Kutz) : What about perceptive comments demonstrating unintended irony in a blog post?
Read more...

Nathan Campbell : Pedantry wins no friends.
Read more...

Pete Kutuzov (Kutz) : "I can’t believe how many people get Dawkins and Hawkings confused as an aside" Perhaps if you spelled their names correctly it'd help with said confusion. :P
Read more...

Lee Shelton : God was up in Heaven, then came down to Earth, then went back up to Heaven, and will one day come down to Earth again. According to the Law of Gravity, what goes up must come down, so I guess we can s
Read more...

Marshall : I agree with Simone, a story is a story, if Driscoll's teenage daughter can't work that out well than there's issues there. But, in saying that, as far as books go Twilight should be considered for th
Read more...

Marshall : kudos Nathan, I have finally found a kindred spirit if I need a place to live....in America
Read more...

simone r : Listened to the twilight one. I think he doesn't get the concept of 'story'. As in 'not real'.
Read more...

Al Bain : Move on. Driscoll is so last year.
Read more...

About St. Eutychus

Eutychus was a young man who fell to his death because the Apostle Paul preached for too long (Acts 20). I've decided to canonise Eutychus and make him the patron saint of my dalliances around the Internet.

About Nathan

Nathan is a Christian.
A husband.
A student. A writer.
A reader.
A coffee drinker.
A “spin twit”.
A consumer.
A fan of stupid gadgets.
A fan of staccato lists in profiles.

Archives

Translate

Subscribe Link

Why Subscribe?
Subscribe with Google
Add to Google
Other Readers
original feed Get the XML
These links above subscribe you to a full RSS feed - feel free to pick and choose feeds based on categories.

RSS Consciousness
RSS Curiosities
RSS Communication
RSS Culture
RSS Christianity
RSS College
RSS Sport
RSS Coffee


Me around the web


Check out my photos on Picasa or Flickr
Watch my videos on YouTube
Read my Google Reader Shared Items
Follow me on Twitter.
Connect on LinkedIn
Friend me on Facebook
Email nm(dot)campbell(at)
gmail(dot)com

Become a "fan"


This is not so much an ego trip as a way for me to have some idea who is out there. Sign up if you don't like commenting.

Links

Recent Comments

Pete Kutuzov (Kutz) : To clarify, that 'bollocks' was directed entirely at the analyst, not our good blogger here.
Read more...

Pete Kutuzov (Kutz) : Bollocks. She doesn't know what she's talking about. Early Ozzie is fantastic. Who gives a toss about whether he stands up to the canons of classical vocal technique? He's not trying to! He just
Read more...

Pete Kutuzov (Kutz) : What about perceptive comments demonstrating unintended irony in a blog post?
Read more...

Nathan Campbell : Pedantry wins no friends.
Read more...

Pete Kutuzov (Kutz) : "I can’t believe how many people get Dawkins and Hawkings confused as an aside" Perhaps if you spelled their names correctly it'd help with said confusion. :P
Read more...

Lee Shelton : God was up in Heaven, then came down to Earth, then went back up to Heaven, and will one day come down to Earth again. According to the Law of Gravity, what goes up must come down, so I guess we can s
Read more...

Marshall : I agree with Simone, a story is a story, if Driscoll's teenage daughter can't work that out well than there's issues there. But, in saying that, as far as books go Twilight should be considered for th
Read more...

Marshall : kudos Nathan, I have finally found a kindred spirit if I need a place to live....in America
Read more...

simone r : Listened to the twilight one. I think he doesn't get the concept of 'story'. As in 'not real'.
Read more...

Al Bain : Move on. Driscoll is so last year.
Read more...

Traffic Report

advertising anti-green Apple art Atheism atheists bacon Ben blog blog design blogging bookofjoe Books branding Christianity climate change Coffee coffee roasting commenting Communication Communication cool ads cool art cool design cool stuff Cricket Curiosities design economics etsy evangelism Facebook flickr fonts From my reader gizmos Godwin's Law google Google Reader Greek guide to better living Hitler How To infographic infographics iphone Izaac Jesus K-Rudd Lego Links lists mario mark driscoll marketing movies Music Nigerian Scam ninja ninjas Obama pacman parenting photography Photos politics pr preaching Puns recipes Robyn scambaiting science segway sermon illustrations shared items Simone SMH star wars Super Mario Bros t-shirt Tetris Tim toilet humour Townsville transformers t shirts Twitter typography vanishing point video web webapps web design wikipedia work xkcd youtube YouTube Tuesday zombies

St. Eutychus is running on a WordPress engine. The cool logo in the header was designed by Ben from Vanishing Point. The author doesn't mind what you do with the content - but attribution is always nice. Current images in the post highlight box at the top right come from http://www.flickr.com/photos/bpbp/ / CC BY-SA 2.0 and Wordle.net