Skip to content

Instantly share code, notes, and snippets.

@FutureMedia
Last active August 29, 2015 14:07
Show Gist options
  • Save FutureMedia/fec59427f3368b103e65 to your computer and use it in GitHub Desktop.
Save FutureMedia/fec59427f3368b103e65 to your computer and use it in GitHub Desktop.
Simple social sharing for WP posts. Requires the post_thumbnail_url() function (a different gist) and https://github.com/cferdinandi/social-sharing#readme
<?php
if ( has_post_thumbnail() ):
$socialimg = post_thumbnail_url($post->ID, $size = 'large');
else:
$socialimg = '';
endif;
?>
<ul class="social-links">
<li><a target="_blank" href="https://facebook.com/sharer.php?u=<?php echo esc_url( get_permalink() ); ?>"><span aria-hidden="true" class="icon-facebook"></span></a></li>
<li><a target="_blank" href="https://pinterest.com/pin/create/button/?url=<?php echo esc_url( get_permalink() ); ?>&description=<?php echo urlencode( get_the_title() ); ?>&media=<?php echo $socialimg; ?>"><span aria-hidden="true" class="icon-pinterest"></span></a></li>
<li><a target="_blank" href="https://twitter.com/intent/tweet?text=<?php echo urlencode( get_the_title() ); ?>&url=<?php echo esc_url( get_permalink() ); ?>"><span aria-hidden="true" class="icon-twitter"></span></a></li>
<li><a target="_blank" href="https://plus.google.com/share?url=<?php echo esc_url( get_permalink() ); ?>"><span aria-hidden="true" class="icon-googleplus"></span></a></li>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment