Skip to content

Instantly share code, notes, and snippets.

@lukewhitehouse
Created September 15, 2015 20:32
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 lukewhitehouse/415da5f800d79bed231e to your computer and use it in GitHub Desktop.
Save lukewhitehouse/415da5f800d79bed231e to your computer and use it in GitHub Desktop.
Social media links

Social media sharing links

Simple social media links for your projects. Initially created for WordPress projects, however, extremely flexible and easily modified.

Instructions

Add this partial to your PHP file, or port this into another language as you see fit.

<?php
// Get access to $post object
global $post;
// Get twitter handle
$twitter = get_field('twitter', 'options');
// define links
$links = array(
'facebook' => 'https://www.facebook.com/sharer/sharer.php?u=' . get_permalink(),
'twitter' => 'https://twitter.com/intent/tweet?text='. get_the_title() .'&url='. get_permalink() .'&via='. $twitter,
'mail' => 'mailto:?subject='. get_the_title() .'&body=Take a look at this link - ' . get_permalink(),
'linkedin' => 'https://www.linkedin.com/shareArticle?mini=true&url='. get_permalink() .'&title='. get_the_title() .'&summary=' . get_the_excerpt(),
'gplus' => 'https://plus.google.com/share?url=' . get_permalink()
);
?>
<nav class="share" role="menu" aria-label="Share Links">
<li class="share__item">
<a href="<?php echo $links['facebook']; ?>" class="share__link"><span class="icon icon--xlarge icon--social-fb"></span><span class="is-hidden">Share this Post on Facebook</span></a>
</li>
<li class="share__item">
<a href="<?php echo $links['twitter']; ?>" class="share__link"><span class="icon icon--xlarge icon--social-tw"></span><span class="is-hidden">Share this Post on Twitter</span></a>
</li>
<li class="share__item">
<a href="<?php echo $links['mail']; ?>" class="share__link"><span class="icon icon--xlarge icon--social-mail"></span><span class="is-hidden">Share this Post via Email</span></a>
</li>
<li class="share__item">
<a href="<?php echo $links['linkedin']; ?>" class="share__link"><span class="icon icon--xlarge icon--social-li"></span><span class="is-hidden">Share this Post on Linked In</span></a>
</li>
<li class="share__item">
<a href="<?php echo $links['gplus']; ?>" class="share__link"><span class="icon icon--xlarge icon--social-gp"></span><span class="is-hidden">Share this Post on Google Plus</span></a>
</li>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment