Skip to content

Instantly share code, notes, and snippets.

@gmaggio
Created July 26, 2014 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmaggio/57832274439ecf4ab732 to your computer and use it in GitHub Desktop.
Save gmaggio/57832274439ecf4ab732 to your computer and use it in GitHub Desktop.
[Wordpress] Add Twitter & Facebook share buttons to posts
<?php
add_action('the_content', 'my_share_this');
/**
* Add Twitter & Facebook share buttons to posts
*
* Sources:
* - http://wordpress.stackexchange.com/questions/125838/how-to-create-really-simple-wordpress-custom-buttons-for-print-facebook-share-a
* - http://www.catswhocode.com/blog/wordpress-snippets-to-interact-with-social-networks
*
*/
function my_share_this($content){
if(is_single()) {
$content .= '<div class="social-profiles clearfix">
<span>Share:</span>
<ul>
<li class="facebook">
<a href="https://www.facebook.com/sharer/sharer.php?u=' . get_permalink() . '" target="_blank" class="facebookIcon" title="Share on Facebook">
</a>
</li>
<li class="twitter">
<a href="https://twitter.com/share?text=' . get_the_title() . '+&ndash;+" target="_blank" class="twitterIcon" title="Tweet on Twitter">
</a>
</li>
</ul>
</div>';
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment