Skip to content

Instantly share code, notes, and snippets.

@danielortiz
Created August 14, 2014 02:10
Show Gist options
  • Save danielortiz/5c84bf5f520635bf2d0e to your computer and use it in GitHub Desktop.
Save danielortiz/5c84bf5f520635bf2d0e to your computer and use it in GitHub Desktop.
Displays share icons in WordPress using Font Awesome that open on pop ups
if( ! function_exists('prefix_share_icons')):
/**
* Display share icons
*/
function prefix_share_icons(){
$share_string = '<a class="share-icon" href="%1$s" title="' . '%2$s' . '" onclick="%3$s">%4$s<span class="hidden">%2$s</span></a>' ;
$share_facebook = sprintf($share_string,
'https://www.facebook.com/sharer/sharer.php?u=' . get_the_permalink() ,
_x('Share on Facebook', 'mytextdomain') ,
'window.open(this.href, \'facebook-share\',\'width=580,height=296\');return false;',
'<i class="fa fa-facebook"></i>');
$share_twitter = sprintf($share_string,
'https://twitter.com/share?text='. htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8') .'&amp;url='. get_the_permalink(),
_x('Share on Twitter', 'mytextdomain'),
'window.open(this.href, \'twitter-share\', \'width=550,height=235\');return false;',
'<i class="fa fa-twitter"></i>');
$share_googleplus = sprintf($share_string,
'https://plus.google.com/share?url=' . get_the_permalink() ,
_x('Share on Google+', 'mytextdomain') ,
'window.open(this.href, \'google-plus-share\', \'width=490,height=530\');return false;',
'<i class="fa fa-google-plus"></i>');
echo '<div class="entry-share">' . $share_facebook . $share_twitter . $share_googleplus . '</div>';
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment