{"id":15,"date":"2012-05-11T18:36:12","date_gmt":"2012-05-11T18:36:12","guid":{"rendered":"http:\/\/www.pat-matthews.com\/stories\/?p=4"},"modified":"2012-05-11T18:36:12","modified_gmt":"2012-05-11T18:36:12","slug":"missing-facebooks-share-button","status":"publish","type":"post","link":"https:\/\/www.pat-matthews.com\/stories\/2012\/05\/11\/missing-facebooks-share-button\/","title":{"rendered":"Missing Facebook&#8217;s Share Button?"},"content":{"rendered":"<p>Do you like Facebook&#8217;s Like button? I don&#8217;t, or at least not in all situations. Sometimes, all I want to do is let help the reader post to their wall. Especially in cases where there are multiple things listed on a page.<!--more--><\/p>\n<p>Facebook&#8217;s deprecated Share button, though, has never worked very well for me, and my clients often don&#8217;t want the &#8220;ShareThis&#8221; branding on their posts.<\/p>\n<p>Enter Facebook&#8217;s javascript library all.js and the good ol&#8217; FB.ui function.<\/p>\n<p>Here&#8217;s how it works:<\/p>\n<p><strong>Step 1: <\/strong>You&#8217;re going to need to include and initialize the facebook javascript. You can do that asynchronously if you want to, but I&#8217;m just going to show you the static way. FB recommends this go just after the &lt;body&gt; tag of your HTML:<\/p>\n<pre>&lt;script src=\"http:\/\/connect.facebook.net\/en_US\/all.js\"&gt; &lt;\/script&gt;<\/pre>\n<p><strong>Step 2: <\/strong>Now\u00a0you have to initialize the script. Put this just below the script from Step 1. Fill in your Facebook App Id where it says &#8220;YourAppId.&#8221; If you need help getting an App Id, post a comment and I&#8217;ll reply.<\/p>\n<pre>&lt;script&gt;\n FB.init({\u00a0\u00a0\u00a0appId:'YourAppId', cookie:true,\u00a0\u00a0status:true,\u00a0\u00a0xfbml:true });\n &lt;\/script&gt;<\/pre>\n<p><strong>Step 3:<\/strong> At last, the fun stuff!\u00a0Here&#8217;s the javascript function that\u00a0lets you do your sharing:<\/p>\n<pre>&lt;script&gt;\nfunction shareonfb() {\n  var fbobj = {\n     method: \"feed\", \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n     link: \"url of this page\", \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n     picture: \"url of picture\", \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n     name: \"The name of the page\", \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n     caption: \"A caption for the share\", \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n     description: \"A description of what's being posted\"\n   };\n   FB.ui(fbobj); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n}\n&lt;\/script&gt;<\/pre>\n<p>See how that works? You&#8217;re initializing an object and passing it to FB.ui. The key is the method (&#8220;feed&#8221;), which tells Facebook to prompt the user to post something on their wall. The other fields are all the data that you&#8217;re using to pre-fill that something. Make sense? It&#8217;s kind of easy once you see how. Those urls, by the way, should be actual urls (i.e., http:\/\/\/www.something.com)<\/p>\n<p><strong>Step 4:<\/strong> Putting the link on your page. Put this code wherever you want the facebook button to appear on your page.<\/p>\n<pre>&lt;a href='javascript:shareonfb();'&gt;\n&lt;img src='URLToPrettyFacebookButton' border='0' alt='Share on Facebook'\/&gt;\n&lt;\/a&gt;\";<\/pre>\n<p><strong>Step 5:<\/strong> Customizing! Want multiple Facebook buttons on your page? Just add some parameters to the shareonfb() function and use them to populate the fbobj.<\/p>\n<p>Pretty cool, huh?<\/p>\n<p>If you want to see it in action, go to<br \/>\n<a href=\"http:\/\/www.smithmag.net\/work-myjob\/story.php?did=230685\">http:\/\/www.smithmag.net\/work-myjob\/story.php?did=230685<\/a><\/p>\n<p>This is what that Facebook button is using.<\/p>\n<p>I hope it&#8217;s helpful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, Facebook&#8217;s Like button isn&#8217;t what you need. Here&#8217;s an option that lets the user post directly to their Facebook wall. It&#8217;s kind of like the old Facebook Share button, but better.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[32,87],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-techie","tag-facebook","tag-social"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6DpYi-f","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pat-matthews.com\/stories\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}