Home » Php » php – Use a custom URL with ShareThis social share plugin

php – Use a custom URL with ShareThis social share plugin

Posted by: admin July 12, 2020 Leave a comment


i would like to know how to use a custom URL with ShareThis social share plugin. for a example i have a post summery on my index.php page taht is linking to my-post.php so what i want to do is to make users share my-post.php from my index page.

here is the code from sharethis.com


<span class='st_facebook_hcount' displayText='Facebook'></span>
<span class='st_twitter_hcount' displayText='Tweet'></span>
<span class='st_googleplus_hcount' displayText='Google +'></span>
<span class='st_pinterest_hcount' displayText='Pinterest'></span>


<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "ur-448a73fe-e6c1-f7a5-f0a5-3912c860fc9e"});</script>
How to&Answers:

You can append a st_url property to each of your span tags which will control the URL that is shared.

<span class='st_facebook_hcount' st_url='http://my.custom.com/url' displayText='Facebook'></span>

Source: https://support.sharethis.com/hc/en-us/articles/218441477-How-to-Customize-which-URL-Text-and-IMG-to-Share


Just use st_url attribute like this:

<span class="st_sharethis" st_url="http://www.yoursite.com/innerpage.php" st_title="inner page title" displayText="ShareThis"></span>


You can just add an extra atrribute like

<div class="sharethis-inline-share-buttons"  data-url="<!--YOUR_URL_GOES_HERE-->"></div>