Last active
February 22, 2018 15:05
-
-
Save fernandiez/28d7f4d7f6d503e0a86f05b52ffd26c5 to your computer and use it in GitHub Desktop.
Social Share Button Snippet simpleshare_socialbuttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function simpleshare_socialbuttons($content) { | |
global $post; | |
if(is_single() || is_page()){ | |
// Get current page URL | |
$simpleshareURL = urlencode(get_permalink()); | |
// Get current page title | |
$simpleshareTitle = str_replace( ' ', '%20', get_the_title()); | |
// Get Post Thumbnail | |
$simpleshareThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); | |
// Construct sharing URL | |
$twitterURL = 'https://twitter.com/intent/tweet?text='.$simpleshareTitle.'&url='.$simpleshareURL.'&via=simpleshare'; | |
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$simpleshareURL; | |
$googleURL = 'https://plus.google.com/share?url='.$simpleshareURL; | |
$linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$simpleshareURL.'&title='.$simpleshareTitle; | |
// Add sharing button at the end of post/page content | |
$content .= '<!-- simpleshare.com social sharing. Get your copy here: http://simpleshare.me/1VIxAsz -->'; | |
$content .= '<div class="simpleshare-social">'; | |
$content .= '<h5>SHARE ON</h5> <a class="simpleshare-link simpleshare-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>'; | |
$content .= '<a class="simpleshare-link simpleshare-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>'; | |
$content .= '<a class="simpleshare-link simpleshare-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>'; | |
$content .= '<a class="simpleshare-link simpleshare-linkedin" href="'.$linkedInURL.'" target="_blank">LinkedIn</a>'; | |
$content .= '</div>'; | |
return $content; | |
}else{ | |
// if not a post/page then don't include sharing button | |
return $content; | |
} | |
}; | |
add_filter( 'the_content', 'simpleshare_socialbuttons'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.simpleshare-link { | |
padding: 2px 8px 4px 8px !important; | |
color: white; | |
font-size: 12px; | |
border-radius: 2px; | |
margin-right: 2px; | |
cursor: pointer; | |
-moz-background-clip: padding; | |
-webkit-background-clip: padding-box; | |
box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); | |
-moz-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); | |
-webkit-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); | |
margin-top: 2px; | |
display: inline-block; | |
text-decoration: none; | |
} | |
.simpleshare-link:hover,.simpleshare-link:active { | |
color: white; | |
} | |
.simpleshare-twitter { | |
background: #00aced; | |
} | |
.simpleshare-twitter:hover,.simpleshare-twitter:active { | |
background: #0084b4; | |
} | |
.simpleshare-facebook { | |
background: #3B5997; | |
} | |
.simpleshare-facebook:hover,.simpleshare-facebook:active { | |
background: #2d4372; | |
} | |
.simpleshare-googleplus { | |
background: #D64937; | |
} | |
.simpleshare-googleplus:hover,.simpleshare-googleplus:active { | |
background: #b53525; | |
} | |
.simpleshare-linkedin { | |
background: #0074A1; | |
} | |
.simpleshare-linkedin:hover,.simpleshare-linkedin:active { | |
background: #006288; | |
} | |
.simpleshare-social { | |
margin: 20px 0px 25px 0px; | |
-webkit-font-smoothing: antialiased; | |
font-size: 12px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment