Skip to content

Instantly share code, notes, and snippets.

@gecugamo
Last active March 20, 2017 19:55
Show Gist options
  • Save gecugamo/80b2a8dc896eafb231dd5740a14cd93b to your computer and use it in GitHub Desktop.
Save gecugamo/80b2a8dc896eafb231dd5740a14cd93b to your computer and use it in GitHub Desktop.
WordPress Social Share
<?php
$site_url = urlencode( get_home_url() );
$post_title = urlencode( get_the_title() );
$post_url = urlencode( get_the_permalink() );
$featured_image = get_img( get_post_thumbnail_id() );
$placeholder_image = 'http://placehold.it/640x480';
$featured_image_src = has_post_thumbnail() ? $featured_image['src'] : $placeholder_image;
function get_img( $attachment_id, $attachment_size = 'full' ) {
return array(
'src' => wp_get_attachment_image_src( $attachment_id, $attachment_size )[0],
'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
);
}
?>
<div class="share">
<h2 class="share__title">Share</h2>
<ul class="share__list">
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--twitter" href="<?php echo "http://twitter.com/intent/tweet?status={$post_title}+{$post_url}"; ?>" target="_blank">Twitter</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--pinterest" href="<?php echo "http://pinterest.com/pin/create/bookmarklet/?media={$featured_image_src}&url={$post_url}&is_video=false&description={$post_title}"; ?>" target="_blank">Pinterest</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--facebook" href="<?php echo "http://www.facebook.com/sharer/sharer.php?u={$post_url}&title={$post_title}"; ?>" target="_blank">Facebook</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--google-plus" href="<?php echo "https://plus.google.com/share?url={$post_url}"; ?>" target="_blank">Google Plus</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--reddit" href="<?php echo "http://www.reddit.com/submit?url={$post_url}&title={$post_title}"; ?>" target="_blank">Reddit</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--delicious" href="<?php echo "http://del.icio.us/post?url={$post_url}&title={$post_title}"; ?>" target="_blank">Delicious</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--digg" href="<?php echo "https://digg.com/submit?url={$post_url}&title={$post_title}"; ?>" target="_blank">Digg</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--stumble-upon" href="<?php echo "http://www.stumbleupon.com/submit?url={$post_url}&title={$post_title}"; ?>" target="_blank">StumbleUpon</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--linkedin" href="<?php echo "http://www.linkedin.com/shareArticle?mini=true&url={$post_url}&title={$post_title}&source={$site_url}"; ?>" target="_blank">LinkedIn</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--google-bookmarks" href="<?php echo "http://www.google.com/bookmarks/mark?op=edit&bkmk={$post_url}&title={$post_title}
"; ?>" target="_blank">Google Bookmarks</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--newsvine" href="<?php echo "http://www.newsvine.com/_tools/seed&save?u={$post_url}&h={$post_title}"; ?>" target="_blank">Newsvine</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--evernote" href="<?php echo "http://www.evernote.com/clip.action?url={$post_url}&title={$post_title}"; ?>" target="_blank">Evernote</a>
</li>
<li class="entry-share__item">
<a class="entry-share__link entry-share__link--email" href="<?php echo "mailto:?subject={$post_title}&body=Check out this site I came across {$post_url}"; ?>" target="_blank">Email</a>
</li>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment