Share webpage url content in Social media using php and Javascript | 2my4edge

17 May 2016

Share webpage url content in Social media using php and Javascript

Now a days social media is most important part in blogging. that will grow our site SEO as well, so here i'm going to tell you one useful tips to share webpage url in top major social media websites by using php with javascript. Let see the code. 

LIVE DEMO                     DOWNLOAD

CODE
<?php 
 $ShareUrl = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
 $Title = 'Share content URL in social media using PHP';
 $Media = 'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWvOdIiG12ffCJuB4q3pygAo8JIVmr_4serpR20MRj6PzghHHaIqPdxhbWyLOlvntAvLoz_rQBUzXKQCUeMqN9V6S2jpw8ty6uVpsbJe2iechFfbT2reo9nbu5NaXlJCxJUcOk_IwrdYFx/s1600/new2.png';
?>


<!-- Share in facebook -->
<a onclick="shareinsocialmedia('https://www.facebook.com/sharer/sharer.php?u=<?php echo $ShareUrl;?>&title=<?php echo $Title;?>')" href="">
<img src="images/facebook.gif" title="share in facebook">
</a>


<!-- Share in twitter -->
<a onclick="shareinsocialmedia('http://twitter.com/home?status=<?php echo $Title; ?>+<?php echo $ShareUrl; ?>')" href="">
<img src="images/twitter.gif" title="share in twitter">
</a>


<!-- Share in google plus -->
<a onclick="shareinsocialmedia('https://plus.google.com/share?url=<?php echo $ShareUrl; ?>')" href="">
<img src="images/gplus.gif" title="share in google plus">
</a>


<!-- Share in Linkedin -->
<a onclick="shareinsocialmedia('http://www.linkedin.com/shareArticle?mini=true&url=<?php echo $ShareUrl; ?>&title=<?php echo $Title; ?>')" href="">
<img src="images/linkedin.gif" title="share in linkexdin">
</a>


<!-- Share in Pinterest -->
<a onclick="shareinsocialmedia('http://pinterest.com/pin/create/button/?url=<?php echo $ShareUrl; ?>&media=<?php echo $Media; ?>&description=<?php echo $Title; ?>')" href="">
<img src="images/pin.gif" title="share in pinterest">
</a>


<!-- Share in Digg -->
<a onclick="shareinsocialmedia('http://www.digg.com/submit?phase=2&url=<?php echo $ShareUrl; ?>&title=<?php echo $Title; ?>')" href="">
<img src="images/digg.gif" title="share in digg">
</a>


<!-- Share in Stumbleupon -->
<a onclick="shareinsocialmedia('http://www.stumbleupon.com/submit?url=<?php echo $ShareUrl; ?>&title=<?php echo $Title; ?>')" href="">
<img src="images/stumble.gif" title="share in stumbleupon">
</a>



<script type="text/javascript" async >
    function shareinsocialmedia(url){
    window.open(url,'sharein','toolbar=0,status=0,width=648,height=395');
    return true;
    }
</script>


I hope this code will helps you a lot, If you don't want pop up window means directly give that below syntax in <a href = " [ SYNTAX ] " target="_blank". > SHARE </a>  it will work. that time no need of the javascript.

SYNTAX
FACEBOOK

http://www.facebook.com/share.php?u=[URL]&title=[TITLE]

TWITTER

http://twitter.com/home?status=[TITLE]+[URL]

GOOGLE PLUS

https://plus.google.com/share?url=[URL]

PINTEREST

http://pinterest.com/pin/create/button/?url=[EncodedURL]&media=[MEDIA]

STUMBLEUPON

http://www.stumbleupon.com/submit?url=[URL]&title=[TITLE]

LINKEDIN

http://www.linkedin.com/shareArticle?mini=true&url=[URL]&title=[TITLE]

DIGG

http://www.digg.com/submit?phase=2&url=[URL]&title=[TITLE]


here i have given few top social media sites only, comment below some more sharing syntax. thanks for visiting. i hope this is very simple way to share webpage url in social media.









RELATED POSTS :

8 comments:

  1. Piyush Patel5/27/2016 12:28 AM

    How Much you earn from this blog, from the starting date till today?

    ReplyDelete
    Replies
    1. Piyush Patel5/30/2016 8:38 PM

      Hey you didn't answer me?
      Please tell me

      Delete
    2. Hey I also want to know, did you get any reply from the blogger? Do let me know...

      Delete
    3. Cool, I'm Earning less money only, I'm using it only for my blog. Going everything fine.

      Delete
    4. Hey I want to know your daily revenue from adsense?

      Delete
  2. hi i implement your script but only send image or url at once time
    please reply

    ReplyDelete
  3. hi i implement your script but only send image url

    ReplyDelete
  4. Thank you very much for writing such an interesting article on this topic. This has really made me think and I hope to read more. upload files free

    ReplyDelete

^