Skip to content

Instantly share code, notes, and snippets.

@BigWhale
Last active April 17, 2019 12:02
Show Gist options
  • Save BigWhale/cda28d4cd6205ac068b2876ff3cd9a0f to your computer and use it in GitHub Desktop.
Save BigWhale/cda28d4cd6205ac068b2876ff3cd9a0f to your computer and use it in GitHub Desktop.
All WordPress plugins for sharing links on social media sucks
/**
* Creates a social media links for various sites
*
* @param string $title Title that is passed to sharing site
* @param string $link permalink that will be shared
* @return string html snippet with icons
*/
function insert_social_links( $link, $title, $image, $desc ) {
$link = esc_url( $link );
$facebook = 'https://www.facebook.com/sharer.php?s=100&p[url]=' . $link . '&p[images][0]=' .$image . '&p[title]=' . $title . '&p[summary]=' . $desc;
$twitter = 'https://twitter.com/intent/tweet?url=' . $link . '&text=' . $title . '&hashtags=endoftheworldisnear';
$google = 'https://plus.google.com/share?url=' . $link;
$pinterest = 'https://pinterest.com/pin/create/bookmarklet/?media=' . $image . '&url=' . $link . ' &is_video=0&description=' . $title;
ob_start(); ?>
<div class="d-social-links">
<div class="d-social-link">
<a onclick="window.open('<?php echo $facebook; ?>','Share on Facebook','width=600,height=400')">
<div class="d-social-icon"><?php insert_icon( 'facebook' ); ?></div>
Facebook
</a>
</div>
<div class="d-social-link">
<a onclick="window.open('<?php echo $twitter; ?>','Share on Twitter','width=600,height=400')">
<div class="d-social-icon"><?php insert_icon( 'twitter' ); ?></div>
Twitter
</a>
</div>
<div class="d-social-link">
<a onclick="window.open('<?php echo $google; ?>','Share on Google','width=600,height=400')">
<div class="d-social-icon"><?php insert_icon( 'google-plus' ); ?></div>
Google Plus
</a>
</div>
<div class="d-social-link">
<a onclick="window.open('<?php echo $pinterest; ?>','Share on Pinterest','width=600,height=400')">
<div class="d-social-icon"><?php insert_icon( 'pinterest' ); ?></div>
Pinterest
</a>
</div>
</div>
<?php
$snippet = ob_get_clean();
return $snippet;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment