facebook save button in wordpress without plugin

Integrate Facebook Save Button to your wordpress posts without a plugin

Yes, of course there are plugins that can do this for you. But if you are like me, you certainly prefer to avoid plugins as much as possible? Why? Although plugins are very helpful, especially if your programming skills aren’t the best, if you can do something simple without a plugin, better do it by coding it yourself. Installing many plugins can slow the loading speed of your site significantly, not to mention that you increase the possibilities of getting hacked because the plugin isn’t coded correctly or it hasn’t been updated for long… And the best reason is the fact that it feels soooo much better when you manage to do things by yourself ;).

So, to integrate a facebook save button to your wordpress site is pretty easy. A facebook save button is actually something a bookmark button which stores website pages that you visit in your facebook profile. In case you want to revisit that specific super hot page that you found once, facebook save button is your friend.

Now, in order to set it up, you first need to paste this code

<span id="fb-root"></span>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

just right after the opening of the <body> tag of your theme. Most commonly you can find it in the header.php template file. Yes, you don’t need to change anything in this code, just copy and paste it like that.

Then you just have to paste this code

<div class="fb-save" data-uri="<?php the_permalink(); ?>" data-size="large"></div>

wherever you want the facebook save button to appear. It can be just below or above your posts content (use the corresponding template file like content.php for example) or wherever you need it. You can change the large to small if you prefer a thinner button. The php code within the data-uri attribute gets dynanically the correct url of the displayed post.

There you are! With just these simple steps you can completely avoid an extra plugin and go enjoy a nice cold beer for making it :).

Leave a Reply

Your email address will not be published. Required fields are marked *