Skip to content

Instantly share code, notes, and snippets.

@graemebryson
Created March 7, 2022 20:13
Show Gist options
  • Save graemebryson/0065ccb6d41e0d5a3baddbda8ec00233 to your computer and use it in GitHub Desktop.
Save graemebryson/0065ccb6d41e0d5a3baddbda8ec00233 to your computer and use it in GitHub Desktop.
Widget — Social Sharing [Facebook, Twitter]
<?php
// ====================================================================================================
// Partials / Components / Widget — Social Sharing
// Output social sharing links
// ====================================================================================================
// Assign item data to vars
$item_link = get_the_permalink();
$share_link_facebook = 'https://www.facebook.com/sharer/sharer.php?u=' . $item_link;
$share_link_twitter = 'https://twitter.com/intent/tweet?url=' . $item_link . '&text=';
// Output widget
?>
<div class="widget--social-sharing">
<p>Found this article useful? Share it with your friends</p>
<nav class="nav--social">
<a href="<?php echo $share_link_facebook; ?>" rel="noopener noreferrer" target="_blank">
<img alt="Share on Facebook" src="/wp-content/uploads/assets/icons/icon__facebook.svg">
</a>
<a href="<?php echo $share_link_twitter; ?>" rel="noopener noreferrer" target="_blank">
<img alt="Share on Twitter" src="/wp-content/uploads/assets/icons/icon__twitter.svg">
</a>
</nav>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment