Skip to content

Instantly share code, notes, and snippets.

@AaronRutley
Last active August 29, 2015 14:16
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 AaronRutley/5d5d37336b3867ff5e59 to your computer and use it in GitHub Desktop.
Save AaronRutley/5d5d37336b3867ff5e59 to your computer and use it in GitHub Desktop.
Social Share - PHP
<?php
function social_share_link($service) {
global $post;
$post_url = get_the_permalink($post->ID);
$post_url_encoded = urlencode($post_url);
$post_title = get_the_title($post->ID);
$twitter_username = 'aaronrutley';
if($service == "twitter") {
echo "https://twitter.com/intent/tweet/?text=".$post_title."&url=".$post_url_encoded."&via=".$twitter_username;
}
if($service == "facebook") {
echo "https://www.facebook.com/sharer/sharer.php?u=".$post_url_encoded;
}
if($service == "linkedin") {
echo "https://www.linkedin.com/shareArticle?mini=true&url=".$post_url_encoded."&title=".$post_title."&source=".$post_url_encoded."&summary=".$post_title;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment