Tag Archives: code

Tweet button and Google “+1” button added

Tweet and Google “+1” buttons were added under every post on this blog. Once again I appreciated the Thematic Framework and the whole concept of child-themes. Thanks to it, putting the buttons on the bottom of each post meant just creating two simple functions in functions.php file of the child-theme.

I decided to publish the code here, because even though it’s quite easy, it still took me some time to figure it out. I hope it will help someone at least a little.

function mytheme_share($content)
$tweetbutton = '<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . get_permalink() .'" data-text="OK1CLD.info: ' . get_the_title() .'" data-count="horizontal" data-via="ok1cld">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';
$plusone = '<g:plusone href="' . get_permalink() .'"></g:plusone>';
$content .= "<p>" . $tweetbutton . $plusone . "</p>";
return $content;
add_filter('the_content', 'mytheme_share', 0);

function mytheme_plusone_js()
{ ?>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<?php }
add_action('thematic_after', 'mytheme_plusone_js');

For more information how to add Tweet button to your webpage see http://twitter.com/about/resources/tweetbutton and if you wanna know how to add “+1” look at http://www.google.com/webmasters/+1/button/.

Posted in General | Also tagged , | Comments closed