Created
May 14, 2013 03:35
-
-
Save wookiecooking/5573479 to your computer and use it in GitHub Desktop.
[WordPress] Add social buttons after posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)).'&layout=standard&show_faces=false&width=450&action=like&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