Skip to content

Instantly share code, notes, and snippets.

@mlbd
Last active April 11, 2018 08:20
Show Gist options
  • Select an option

  • Save mlbd/22bbdbfaae79f989295e0af41053a862 to your computer and use it in GitHub Desktop.

Select an option

Save mlbd/22bbdbfaae79f989295e0af41053a862 to your computer and use it in GitHub Desktop.
/**
* Social Share buttons
*/
if ( !class_exists( 'Pixiefy_Social_Btns' ) ) {
class Pixiefy_Social_Btns {
public $args = '';
public function __construct($args){
$this->args = $args;
}
public function get_thumbnail(){
return (has_post_thumbnail()) ? get_the_post_thumbnail_url(get_the_ID(),'full') : '';
}
public function get_title(){
return ( get_the_title() ) ? str_replace( ' ', '%20', get_the_title()) : '';
}
public function get_url(){
return ( get_the_permalink() ) ? urlencode(get_permalink()) : '';
}
public function social_buttons(){
if ( is_singular() || is_single() ) {
$ss_thumb = $this->get_thumbnail();
$ss_title = $this->get_title();
$ss_url = $this->get_url();
$twitter_url = 'https://twitter.com/intent/tweet?text='.$ss_title.'&url='.$ss_url.'';
$facebook_url = 'https://www.facebook.com/sharer/sharer.php?display=popup&u='.$ss_url.'&title='.$ss_title.'';
$whatsapp_url = 'whatsapp://send?text='.$ss_title . ' ' . $ss_url;
$linkedin_url = 'https://www.linkedin.com/shareArticle?mini=true&url='.$ss_url.'&title='.$ss_title;
if(!empty($ss_thumb)) {
$pinterest_url = 'https://pinterest.com/pin/create/button/?url='.$ss_url.'&media='.$ss_thumb.'&description='.$ss_title;
} else {
$pinterest_url = 'https://pinterest.com/pin/create/button/?url='.$ss_url.'&description='.$ss_title;
}
$gplus_url = 'https://plus.google.com/share?url='.$ss_url.'';
$delicious_url = 'http://del.icio.us/post?url='.$ss_url.'&title='.$ss_title.'';
$stumbleupon_url = 'http://www.stumbleupon.com/submit?url='.$ss_url.'&title='.$ss_title.'';
$reddit_url = 'http://reddit.com/submit?url='.$ss_url.'&title='.$ss_title.'';
$gmail_url = 'https://mail.google.com/mail/?ui=2&view=cm&fs=1&tf=1&su='.$ss_title.'&body=Link: '.$ss_url.'';
$tumblr_url = 'http://www.tumblr.com/share/link?url='.$ss_url.'&name='.$ss_title.'&description='.$ss_title.' - '.$ss_url.'';
$email = 'mailto:?subject='.$ss_title.'&body=Link: '.$ss_url.'';
$share_content = '';
if ( isset($this->args) && is_array($this->args) && !empty($this->args) ) :
$share_content = '<div class="seoleader_social_share_links"><ul>';
if (in_array('facebook', $this->args)) {
$share_content .= '<li><a class="fb_share_btn" href="'. esc_attr( $facebook_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>';
}
if (in_array('twitter', $this->args)) {
$share_content .= '<li><a class="tw_share_btn" href="'. esc_attr( $twitter_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>';
}
if (in_array('linkedin', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $linkedin_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-linkedin" aria-hidden="true"></i></a></li>';
}
if (in_array('gplus', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $gplus_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-google-plus" aria-hidden="true"></i></a></li>';
}
if (in_array('whatsapp', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $whatsapp_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-whatsapp" aria-hidden="true"></i></a></li>';
}
if (in_array('pinterest', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $pinterest_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-pinterest" aria-hidden="true"></i></a></li>';
}
if (in_array('delicious', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $delicious_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-delicious" aria-hidden="true"></i></a></li>';
}
if (in_array('stumbleupon', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $stumbleupon_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-stumbleupon" aria-hidden="true"></i></a></li>';
}
if (in_array('reddit', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $reddit_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-reddit" aria-hidden="true"></i></a></li>';
}
if (in_array('tumblr', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $tumblr_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-tumblr" aria-hidden="true"></i></a></li>';
}
if (in_array('gmail', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $gmail_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-google" aria-hidden="true"></i></a></li>';
}
if (in_array('email', $this->args)) {
$share_content .= '<li><a class="ln_share_btn" href="'. esc_attr( $email_url ) .'" target="_blank" rel="nofollow"><i class="fa fa-envelope-o" aria-hidden="true"></i></a></li>';
}
$share_content .= '</ul></div>';
endif;
return $share_content;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment