Skip to content

Instantly share code, notes, and snippets.

@wookiecooking
Created May 14, 2013 03:35
Show Gist options
  • Save wookiecooking/5573479 to your computer and use it in GitHub Desktop.
Save wookiecooking/5573479 to your computer and use it in GitHub Desktop.
[WordPress] Add social buttons after posts
<?php
/* Facebook */
add_filter('the_content', 'likebutton', 99); // Display underneath the_content
function likebutton ()
{
echo '<iframe src="http://www.facebook.com/plugins/like.php?href='.urlencode(get_permalink($post->ID)).'&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>';
} ?>
<?php
/* Pinterest */
add_filter('the_content', 'pinbutton', 99);
function pinbutton () {
if (has_post_thumbnail( $post->ID )){ ?>
<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
<? } else { ?>
<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
<? }
} ?>
<?php
/* google plus button */
add_filter('the_content', 'gplus', 99);
function gplus () { ?>
<div class="g-plusone"></div>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<? } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment