Skip to content

Instantly share code, notes, and snippets.

@gdarko
Last active July 23, 2017 13:06
Show Gist options
  • Save gdarko/867ba44d440a0de0f92fcca34a82b8b7 to your computer and use it in GitHub Desktop.
Save gdarko/867ba44d440a0de0f92fcca34a82b8b7 to your computer and use it in GitHub Desktop.
WordPress Social Sharing Icons
/**
* This is very basic styling
*/
.dg-sharing-icons ul.dg-sharing-icons-inner li i.fa {
color: gray;
}
.dg-sharing-icons ul.dg-sharing-icons-inner li {
display: inline-block;
margin-right: 15px;
}
.dg-sharing-icons ul.dg-sharing-icons-inner {
list-style-type: none;
padding-left: 0;
margin-left: 0;
text-align: center;
}
<?php
/**
* Function that will output sharing icons for the current page/post
* Requirements
* 1.) Font awesome
* Note: This gist includes very basic styling, it is up to you to style them better.
*
* @author Darko Gjorgjijoski <dg@darkog.com>
*/
function dg_sharing_icons() {
global $post;
$permalink = get_permalink( $post );
$featured = get_the_post_thumbnail_url( $post, 'full' );
$url_facebook = esc_url( '//www.facebook.com/sharer/sharer.php?u=' . $permalink );
$url_twitter = esc_url( '//twitter.com/share?url=' . $permalink . '&text=' . $post->post_title );
$url_googleplus = esc_url( '//plus.google.com/share?url=' . $permalink );
$url_pinterest = esc_url( '//pinterest.com/pin/create/button/?url=' . $permalink . '&media=' . $featured . '&description=' . $post->post_title . ' : ' . $permalink );
$url_xing = esc_url('//www.xing.com/spi/shares/new?image='.$featured.'&sc_p=b7910_cb&title='.$post->post_title.'&url='.$permalink);
$url_email = esc_url( 'mailto:?subject=' . $post->post_title . '&body=' . $permalink );
?>
<div class="dg-sharing-icons">
<ul class="dg-sharing-icons-inner">
<li>
<a href="javascript:void(0);"
onclick="window.open('<?php echo $url_facebook; ?>', '','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"
target="_blank"
title="Share On Facebook">
<i class="fa fa-facebook"></i>
</a>
</li>
<li>
<a href="javascript:void(0);"
onclick="window.open('<?php echo $url_twitter; ?>','_blank','width=800,height=300')"
title="Share On Twitter">
<i class="fa fa-twitter"></i>
</a>
</li>
<li>
<a href="javascript:void(0);"
onclick="window.open('<?php echo $url_googleplus; ?>','','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=800');return false;"
title="Share On Google Plus">
<i class="fa fa-google-plus"></i>
</a>
</li>
<li>
<a href="javascript:void(0);"
onclick="window.open('<?php echo $url_pinterest; ?>','pinIt','toolbar=0,status=0,width=800,height=500');"
title="Share On Pinterest">
<i class="fa fa-pinterest"></i>
</a>
</li>
<li>
<a
href="javascript:void(0);"
onclick="window.open('<?php echo $url_xing; ?>','','toolbar=0,status=0,width=800,height=500');"
title="Share on XING">
<i class="fa fa-xing"></i>
</a>
</li>
<li>
<a href="mailto:?subject=<?php echo $post->post_title; ?>&body=<?php echo $permalink; ?>"
data-title="Contact us"
title="Contact us">
<i class="fa fa-paper-plane"></i>
</a>
</li>
</ul>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment