How to define Share URL in Social Buttons (and Why you Should)

Using Facebook LIKE button or other social media share buttons, it is useful to define the URL of the page you want to share. It is not requested (by default), as the page URL is used.

But the page URL may contain query string from the site which refers to your page (e.g. Google Adsense or other similar services) for tracking purposes. In this case Facebook (or any other social network) probably will not recognize the URL and the number of shares will appear as zero (0). The same problem may occur with Disqus comments.

So, I recommend to define somewhere your page URL (probably dynamically), for example:

$share_url = 'http://www.your-site.com/' . $post_url;

and use this parameter to any share button (see the following examples).

Examples

Facebook

Define href parameter for Facebook LIKE button:

<fb:like href="<?php print $share_url ?>"
                 data-layout="box_count"
                 show_faces="false"
                 data-send="true"
                 font=""></fb:like>

Twitter

Define data-url parameter for Twitter share button:

<a href="https://twitter.com/share"
   class="twitter-share-button"
   data-url="<?php print $share_url ?>"
   data-count="vertical"
   data-via="your_username_here"
   data-lang="el">Tweet</a>

Google plus

Define data-href parameter for Google +1 button:

<div class="g-plusone"
         data-href="<?php print $share_url ?>"
         data-size="tall"></div>

Linkedin

Define data-url parameter for Linkedin share button:

<script type="IN/Share"
        data-url="<?php print $share_url ?>"
        data-counter="top">
</script>

StumbleUpon

Define location parameter for StumbleUpon badge:

<su:badge
        layout="5"
        location="<?php print $share_url ?>">
</su:badge>

Disqus

Define disqus_url parameter for Disqus implementation (general code):

<div id="disqus_thread"></div>
<script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'pontikisnet'; // required: replace example with your forum shortname
        var disqus_url = '<?php print $share_url ?>';

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
                var dsq = document.createElement('script');
                dsq.type = 'text/javascript';
                dsq.async = true;
                dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
</script>
<noscript>Please enable JavaScript to view the <a
                href="http://disqus.com/?ref_noscript">comments powered by
                Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by
        <span class="logo-disqus">Disqus</span></a>

Your comments are welcome!