DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Nowadays, most bloggers are using Facebook and Twitter to promote their posts. In today’s recipe, I’m going to show you how you can easily add Twitter and Facebook buttons to the bottom of your posts.

Paste the code below into your functions.php file, save it, and you’re done.

function share_this($content){
    if(!is_feed() && !is_home()) {
        $content .= '<div class="share-this">
                    <a href="http://twitter.com/share"
                    <script type="text/javascript"
                    <div class="facebook-share-button">
scrolling="no" frameborder="0" style="border:none;
overflow:hidden; width:200px; height:21px;"
    return $content;
add_action('the_content', 'share_this');

Thanks to Dev7Studios for this awesome recipe!



  1. Is it possible for this to be above the content?

  2. This is a really useful bit of code. Social media is such an important element that people now want integrating into their websites as standard. I think that I will definitely be using this in the future as the code is so simple to locate for me now and I know exactly what to do with it. Thank you

  3. Your all tricks and hacks are jakkash but a screenshot or demo will be better if you provide. 🙂

  4. hello
    very goog trick
    but how placing that above the content? and how to set the size and the position?
    it’s a bit “rough” as it; it will be goog to tun the code a little bit in order to get a nice result.
    best regards

  5. I paste this code into the functions.php file of my blog theme but it displays error message. Please tell me what to do.

  6. Hello,
    for me it is the same, I paste this peace of code exactly so in functions.php. I always get errors – headers already sent by (output started at… and so on. What can I do?

  7. @Frank: Try removing all empty spaces between the

    @Sam: You can place the share buttons above the post by removing the . infront of content. Check here for details: http://www.wpspells.com/add-fb-twitter-gplus-share-buttons/

  8. This is neat. Thanks. Also I would like to know if I should go for iframe or javascript?

Leave a Comment

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