to top
  • sajidztech@gmail.com

  • +880 01626083068

Create a Dynamic Share button in WordPress posts without Plugins

share-button-customize

Create a Dynamic Share button in WordPress posts without Plugins

Most of the cases we use wordPress to create our websites. And in this websites most of the times we post blogs. And it may be current news related, sports related, people related, politics related and so on. And their may have a lot of viewers who come across your site to read your blogs. And in some cases they really love your blogs and want to share in in their social media. In this case it may be shared via Facebook, Twitter, Linkedin, Pinterest, Instagram, Snapchat, And so on.

For that reason in wordpress we need to make a share button. And in YouTube and Google their have a lot of suggestions to create a socials hare buttons. And for that they suggest your to use a plugin. And sometimes these plugins are really inefficient because here they use your data and some cases it also deactivate your other plugins and in some cases they change the version then it’s really difficult to us. And in some case we need to customize those buttons too by own and in this case we can’t use these plugins.

So in this post I am going to talking with you how you can create a Social media share plugin for your wordpress website and make it effective.

So in this case I have the link of Facebook, Twitter, Linkedin and Pinterest Sharing links. But for other social media too you can create those by a brainstorming.

<?php $postUrl = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; ?>
<ul>
<li><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $postUrl; ?>" title="Share on Facebook">facebook</a></li>
<li><a target="_blank" href="https://twitter.com/intent/tweet?url=<?php echo $postUrl; ?>&text=<?php echo the_title(); ?>&via=<?php the_author_meta( 'twitter' ); ?>" title="Tweet this">Twitter</a></li>
<li><a target="_blank" href="https://www.linkedin.com/sharing/share-offsite/?url=<?php echo $postUrl; ?>" title="Share on LinkedIn">Linkedin</a></li>
<li><a target="_blank" href="https://pinterest.com/pin/create/button/?url=<?php echo $postUrl; ?>" title="Share on Pinterest">Pinterest</a></li>
</ul>

Here this will share the whole page content with thumbnails in your Facebook, Twitter, Linkedin, Pinterest. So in which you want to available your viewers to share this post use this code and design it as your wish to make this code as your wish.

And if you want to add more social media then share a thing that social media and in the URL you will find an URL and from that URL you need to copy the URL and paste it where you need and change the URL link where it has the post name give here

&text=<?php echo the_title(); ?>

where have page URL give here

?url=<?php echo $postUrl; ?>

And that’s it for you to make a share button.

By this way I hope you can also create a share button in your wordpress site so that from here the post viewers also share the post as their wish.

 

Share this Blog:

Comments (0)

Leave A Comment

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

© All Right Reserved with SajidzTech