Blog for web designers

WordPress custom social share

Sharing articles and post is a very good feature to promote our articles. There are lots of plugin that can perform this task. But using plugin is not always a good option especially when the whole plugin work can be done by couple lines of code. Below code will perform to share your existing page, article or post to specific social media.

Go to your theme folder
The path to your theme can be:
wp-content/themes/your-theme/

Just copy the code and paste it into you page.
post share code
Best files to keep the code.

  • single.php
  • header.php
  • page.php
  • footer.php

Code


<div class="post-share">

<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"><span class="share-box"><i class="fa fa-facebook"></i></span></a>
<a target="_blank" href="https://twitter.com/home?status=Check%20out%20this%20article:%20<?php the_title(); ?>%20-%20<?php the_permalink(); ?>"><span class="share-box"><i class="fa fa-twitter"></i></span></a>
<a target="_blank" href="https://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $pin_image; ?>&description=<?php the_title(); ?>"><span class="share-box"><i class="fa fa-pinterest"></i></span></a>
<a target="_blank" href="https://plus.google.com/share?url=<?php the_permalink(); ?>"><span class="share-box"><i class="fa fa-google-plus"></i></span></a>


</div>

Santosh Shah

My name is Santosh Shah and blogs at santosh-shah.com


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.