Adding the following snippet to your theme’s functions.php file, you will be able to add Twitter and Facebook buttons to your posts. It will display both Facebook and Twitter buttons at the bottom of this post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function share_this($content){ if(!is_feed() && !is_home()) { $content .= '<div class="share-this"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a> <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <div class="facebook-share-button"> <iframe src="http://www.facebook.com/plugins/like.php?href='. urlencode(get_permalink($post->ID)) .'&layout=button_count&show_faces=false&width=200&action=like&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe> </div> </div>'; } return $content; } add_action('the_content', 'share_this'); |
Snippet Source/Credit: WPRecipes