Skip to content

Instantly share code, notes, and snippets.

@reidelliott
Last active June 7, 2021 21:07
Show Gist options
  • Save reidelliott/4c717ad346855398d09b7e3fc4176164 to your computer and use it in GitHub Desktop.
Save reidelliott/4c717ad346855398d09b7e3fc4176164 to your computer and use it in GitHub Desktop.
Function for social share links in WP using Font Awesome icons
/**
* Share Links
*/
function share_links() {
$home_url = esc_url( home_url( '/') );
$slug = basename( get_permalink() );
?>
<div class="share-links-container align-middle">
<ul class="share-links list-unstyled text-center text-sm-right mt-3 mb-3 mb-sm-0">
<li class="linkedin list-inline-item">
<a href="https://www.linkedin.com/shareArticle?url=<?php if (!is_front_page()) { echo $home_url . $slug; } else { echo $home_url; } ?>&title=<?php echo get_bloginfo('name') . ' – ' . get_the_title(); ?>" target="_blank"><i class="fa fa-linkedin"></i><span class="sr-only">Share</span></a>
</li>
<li class="facebook list-inline-item">
<a href="http://www.facebook.com/sharer.php?u=<?php if (!is_front_page()) { echo $home_url . $slug; } else { echo $home_url; } ?>" target="_blank"><i class="fa fa-facebook"></i><span class="sr-only">Share</span></a>
</li>
<li class="twitter list-inline-item">
<a href="http://twitter.com/share?text=<?php echo get_bloginfo('name') . ' – ' . get_the_title(); ?>&url=<?php if (!is_front_page()) { echo $home_url . $slug; } else { echo $home_url; } ?>" target="_blank"><i class="fa fa-twitter"></i><span class="sr-only">Tweet</span></a>
</li>
<li class="pinterest list-inline-item">
<a href="https://pinterest.com/pin/create/button/?url=<?php if (!is_front_page()) { echo $home_url . $slug; } else { echo $home_url; } ?>&media=<?php the_post_thumbnail_url( 'full' ); ?>&description=<?php echo get_bloginfo('name') . ' – ' . get_the_title(); ?>" target="_blank"><i class="fa fa-pinterest"></i><span class="sr-only">Pin</span></a>
</li>
<li class="email list-inline-item">
<a href="mailto:?subject=<?php echo get_bloginfo('name') . ' – ' . get_the_title(); ?>&amp;body=<body copy here><?php if (!is_front_page()) { echo $home_url . $slug; } else { echo $home_url; } ?>" target="_blank"><i class="fa fa-envelope"></i><span class="sr-only">Email</span></a>
</li>
</ul>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment