Social Share Buttons Without a Plugin

Most sharing plugins are too loaded with options, and tend to slow down my sites.

I wrote this simple script to counter that.

Create this file and name it “sharebuttons.php”. Upload it to your theme directory.

<div id="sharethis">
<h3 class="sharethis">Share This:
<a style="margin-right:5px;margin-left:10px;" rel="nofollow" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Facebook" target="_blank"><img src="<?php echo bloginfo('stylesheet_directory') ?>/images/fbuser.png"></a>
<a style="margin-right:5px;" rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_permalink(); ?>" title="Share this with your Twitter followers" target="_blank"><img src="<?php echo bloginfo('stylesheet_directory') ?>/images/twuser.png"></a>
<a style="margin-right:5px;" rel="nofollow" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo bloginfo('stylesheet_directory') ?>/images/liuser.png"></a>
<a style="margin-right:5px;" rel="nofollow" href="https://plus.google.com/share?url=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo bloginfo('stylesheet_directory') ?>/images/gplususer.png"></a>
<a style="margin-right:5px;" href="javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());"><img src="<?php echo bloginfo('stylesheet_directory') ?>/images/pinuser.png"></a>
</h3>
</div>

You will also need to create your images, and style the div as you like.

┬áThen, to add the div to pages or posts, just put this in your template file, immediately following (or just before) the_content() — or wherever you want the buttons to appear:

<?php
include('sharebuttons.php');
?>

Comments are closed.

Skip to toolbar