Php tutorials

Share Your Website Post To Social Media using php

Google+ Pinterest LinkedIn Tumblr

Share Your Website Post To Social Media using php

Share your website post to social media using php. Everyone want to share their post in social media regularly to get increase the page views and also website view. So the social media is the best way to promote our content to reach everyone. When ever we write our post we directly update this post into our social media using php

Here I am written sharing code, Just click social media icons it will share automatically to your social media timeline

Here I have get our website details description and content using php

<?php $url="https://www.developerdesks.com/";
$name="Share post links articles to social network with Yoursite"; 
$caption="social sharing developer desks"; 
$description="Write some fo the description about your content."; 
$logo="https://www.developerdesks.com/logo.png"; ?>

Here we going to add Facebook and Google plus sharing

<html>
<head>
<title>Share links | Developerdesks</title>
</head>
<body>
<div class="gplus">
<!--google+ sharing --> 
<a href="https://plus.google.com/share?url={<?php echo $url;?>}" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
<img width="200" src="google+.png"/> </a> 
</div>
<!--/google+ sharing --> 
<div class=""fb-class">
<!-- fb sharing -->
<a href="#" id="shareonfacebook"><img src="facebook.jpg"></a>
<div class="fb-share-button" data-href="<?php echo $url; ?>" data-layout="button_count">
</div></a>
</div> </body> </html>

Add Javascript for sharing link
Het your facebook api id from the developers facebook page

Find how to get app id – Here

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script> $(document).ready(function () { $('#shareonfacebook').click(function (e) {  var name ='<?php echo $name; ?>'; var caption ='<?php echo $caption; ?>'; var picture ='<?php echo $picture; ?>'; var description ='<?php echo $description; ?>'; var link ='<?php echo $url; ?>';  e.preventDefault(); FB.ui( { method: 'feed', name: name, link: link, caption: caption, picture: picture, description: description, message: '' }); }); });  </script> <script> FB.init({appId: 'yourappid', status: true, cookie: true, xfbml: true}); </script> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=yourid&version=v2.0"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>

Here we added the javascript for post article. now you can used ur post to share in social media

[sociallocker]

[/sociallocker]

I'm Rajasekar - Web developer, Freelancer, Blogger and Owner of DeveloperDesks. From India lives in Bahrain. I love to do coding, Creating websites and trying different with code and designs. You Can Hire Me

Write A Comment