Social sharing links without addthis etc?

103 views Asked by At

Im wanting to ditch addthis because it slows my page load time considerably. The main benefit off addthis to me was that it detected the page being shared and the user wouldn't have to copy and paste the page link.

If i go with the stand alone links the big services like G plus offer, you need to manually edit the code on each page with the link to the page being shared.

Eg: https://plus.google.com/share?url=www.site.com/page.htm

This would be very time consuming.

Is there a way to script something so that it appends the page that its on into the link for g plus, twitter, flickr etc?

Or any other known way to automate the process?

1

There are 1 answers

4
Reena Parekh On

To append page URL dynamically at the end of your G+ URL:

This will append your page URL without protocol (HTTP or HTTPS)

  <script type="text/javascript">
        var GooglePlusURL = 'https://plus.google.com/share?url=' + window.location.host + window.location.pathname 
  </script>

OR this will append your page URL with protocol (HTTP or HTTPS)

 <script type="text/javascript">
            var GooglePlusURL = 'https://plus.google.com/share?url=' + window.location.href
 </script>

This way separate GooglePlus Url will be created for every page.

Add the code in a header/footer file or some common file that is used on every page. This way your javascript code will get appended on every page automatically.

In most cases, header and footers are common in all pages and hence these files are included on every page. However, it depends on the framework you are using and the coding standard that you are following.

Hope this helps!!