to top

  • +(000) 123456789

Create a Dynamic Share button in WordPress posts without Plugins


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']}"; ?>
<li><a target="_blank" href="<?php echo $postUrl; ?>" title="Share on Facebook">facebook</a></li>
<li><a target="_blank" href="<?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="<?php echo $postUrl; ?>" title="Share on LinkedIn">Linkedin</a></li>
<li><a target="_blank" href="<?php echo $postUrl; ?>" title="Share on Pinterest">Pinterest</a></li>

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 your pots:

Comments (0)

leave a comment

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

about us

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae tempora temporibus ex necessitatibus asperiores, enim similique repudiandae iste modi aspernatur.

© 2020. Theme Coder all tights reserved