How to add share button in my website?

9.6k Views Asked by At

My website is generate a unique id or link to every user so how I can add share button to let user share his link in FB for example ? My website generate code is :

$uid_code = md5($user);

echo '<br /><center><div id="codewrap">Copy link and share it <br /><code>'.$sksiteurl.'index.php?nav=test&id='.$uid_code.'</code></div></center>';
2

There are 2 best solutions below

2
On

First Put a button on where you want to add sharing link like below

<button class="social" data-url="$add-your-page-url" title="Share on Facebook">
    <i class="fa fa-facebook"></i>
</button>

Now by this jQuery you can share any page link

<script>

$(document).on('click','.social',function(e){
    var url  = $(this).data("url");
    if(type=="fb")  var url = 'http://www.facebook.com/sharer.php?u=';
    mini=true&url=';
    window.open(url,'',"width=500,height=500,left=400px,top=100px,location=no");
});

</script>

Try this.

0
On

For reference use this link:

https://www.daddydesign.com/wordpress/how-to-create-a-custom-facebook-share-button-with-a-custom-counter/

<?php
function fb_count() {
global $fbcount;
$facebook = file_get_contents('http://api.facebook.com/restserver.php?method=links.getStats&urls=https://www.daddydesign.com/how-to-create-a-custom-facebook-share-button-with-a-custom-counter/');
$fbbegin = '<share_count>'; $fbend = '</share_count>';
$fbpage = $facebook;
$fbparts = explode($fbbegin,$fbpage);
$fbpage = $fbparts[1];
$fbparts = explode($fbend,$fbpage);
$fbcount = $fbparts[0];
if($fbcount == '') { $fbcount = '0'; }
}       
?>

This will help you! Thanks