It’s only recently that I started with CodeHandbook using Wordpress. I’m completely a new bee when it comes to wordpress and as far I have heard from a few friends, it’s quite simple to get started and there are tons of plugins to make everything work for you right out of the box.

I started blogging on CodeHandbook and used to share my tutorials and article on Facebook, Twitter and Google plus. Then I saw a number of websites having the social media share button right above their articles which made it quite easier for the reader to share the post. So, I started searching for a plugin to add the share buttons above my articles and I stumbled upon GetSocial plugin. It was a nice plugin and perfectly suited my needs. But there was an issue. While sharing using Twitter, if I wanted to include my twitter handle, I have to upgrade to a paid version (which I wasn’t really willing to).

So, I thought why not try to add Twitter, Facebook and Google Plus share to posts without using any plugin.

To create a twitter share button, go to the twitter button resources. Select the share button and enter the required details and you should get the required code for the twitter share button. Here is how my twitter share link looked like:

<a href="https://twitter.com/share" class="twitter-share-button" data-via="codehandbook" data-related="codehandbook">Tweet</a>

For the Google Plus share , you need to the following script and code.

<script src="https://apis.google.com/js/platform.js" async="" defer="" gapi_processed="true"></script>
<div style="position: absolute; width: 450px; left: -10000px;" id="___plusone_0"><iframe ng-non-bindable="" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="position:absolute;top:-10000px;width:450px;margin:0px;border-style:none" tabindex="0" vspace="0" width="100%" id="I0_1621965411431" name="I0_1621965411431" src="https://apis.google.com/u/0/se/0/_/+1/fastbutton?usegapi=1&amp;size=medium&amp;origin=http%3A%2F%2Flocalhost%3A4000&amp;url=https%3A%2F%2Fwww.codehandbook.org%2Fhow-to-add-twitter-facebook-google-plus-share-to-self-hosted-wordpress-posts%2F&amp;gsrc=3p&amp;jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en_GB.e0zmNYwRirY.O%2Fam%3DAQ%2Fd%3D1%2Frs%3DAGLTcCOwZVd7GHtTCczV_JXbP7WbEEQ7IQ%2Fm%3D__features__#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&amp;id=I0_1621965411431&amp;_gfid=I0_1621965411431&amp;parent=http%3A%2F%2Flocalhost%3A4000&amp;pfname=&amp;rpctoken=17327646" data-gapiattached="true"></iframe></div><g:plusone size="medium" data-gapiscan="true" data-onload="true" data-gapistub="true"></g:plusone>

Size can be small, medium and tall.

For the Facebook share button, go to the facebook official docs and enter you URL and get the required code. Include the JavaScript SDK code right after the opening body tag. So, go to you wordpress theme folder and edit the header.php file to include the JavaScript SDK code after the body tag. Here is how my Fb share code looks like:

I have modified the data-href to get the particular post URL when the Facebook share button is clicked.

Now finally open up the content-single.php file from the themes folder and add the following code before the entry- content class element.

<div class="media-share">
    <div class="twitterDiv">
       <a href="https://twitter.com/share" class="twitter-share-button" data-via="codehandbook" data-related="codehandbook">Tweet</a>
    </div>
    <script src="https://apis.google.com/js/platform.js" async="" defer="" gapi_processed="true"></script>
    <div class="googlePlusDiv">
       <div style="position: absolute; width: 450px; left: -10000px;" id="___plusone_1"><iframe ng-non-bindable="" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="position:absolute;top:-10000px;width:450px;margin:0px;border-style:none" tabindex="0" vspace="0" width="100%" id="I1_1621965411436" name="I1_1621965411436" src="https://apis.google.com/u/0/se/0/_/+1/fastbutton?usegapi=1&amp;size=medium&amp;origin=http%3A%2F%2Flocalhost%3A4000&amp;url=https%3A%2F%2Fwww.codehandbook.org%2Fhow-to-add-twitter-facebook-google-plus-share-to-self-hosted-wordpress-posts%2F&amp;gsrc=3p&amp;jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en_GB.e0zmNYwRirY.O%2Fam%3DAQ%2Fd%3D1%2Frs%3DAGLTcCOwZVd7GHtTCczV_JXbP7WbEEQ7IQ%2Fm%3D__features__#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&amp;id=I1_1621965411436&amp;_gfid=I1_1621965411436&amp;parent=http%3A%2F%2Flocalhost%3A4000&amp;pfname=&amp;rpctoken=35219510" data-gapiattached="true"></iframe></div><g:plusone size="medium" data-gapiscan="true" data-onload="true" data-gapistub="true"></g:plusone>
    </div>
    <div class="facebookDiv">
        <div class="fb-share-button" data-href="<?php echo get_permalink(); ?>" data-layout="button_count"></div>
    </div>
</div>

Now you should be able to view the Twitter, Facebook and Google Plus share buttons above your articles or tutorials.
Happy Hacking :)