Custom Social Share Buttons Integration
Custom social share buttons are most required things on a web site, while developing each site we concentrate how we can use all buttons,icons images are very close to the template. In this case the social share icons or like buttons are crazy. They looks same on major site but many sites used custom icons for social share buttons.
Before starting the integration we can check what are the advantages of using custom social share buttons on your websites.
- The social share button so close to your template design.
- There is no load of external JS files for your custom share button, It will improve the page loading speed.
- Easy integration and no loading delay.
- Custom social share button gives an option to share the dynamic contents.(not from Open graph protocols).
This article will help to create custom social share buttons for Facebook, Google Plus, Pinterest, Tumblr , Twitter and Linked In. And also describe how you can share dynamically generated data to these social media sites.
For Facebook Custom share button.
<a id="ref_fb" href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $description;?>&p[url]=<?php echo urlencode($share_url);?>&
p[images][0]=<?php echo $image_url;?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600'); return false;"><img src="your custom facebook share button image" alt=""/></a>
Custom Twitter Share Button
<a id="ref_tw" href="http://twitter.com/home?status=<?php echo $title; ?>+<?php echo urlencode($share_url);?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom twitter share button image" alt=""/></a>
Custom Google Plus share button
<a id="ref_gp" href="https://plus.google.com/share?url=<?php echo urlencode($share_url);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false"><img src="your custom gplus share button image" alt=""/></a>
Custom Pinterest share button.
<a id="ref_pr" href="http://pinterest.com/pin/create/bookmarklet/?media=<?php echo urlencode($share_image);?>&
url=<?php echo urlencode($share_url);?>&
is_video=false&description=<?php echo $description;?>"
onclick="javascript:window.open(this.href, '_blank', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom pin share button image" alt=""/></a>
Custom Tumblr share button
<a id="ref_tum" href="http://www.tumblr.com/share/photo?source=<?php echo urlencode($share_image);?>&caption=<?php echo $description;?>&clickthru=<?php echo urlencode($share_url);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom pin share button image" alt=""/></a>
Custom Linked In share button.
<a id="ref_lkd" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode($share_url);?>&title=<?php echo strip_tags($title); ?>&source=<?php echo urlencode($siteurl);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom pin share button image" alt=""/></a>
Make sure all the title description are properly formatted ie, special chars should be removed and well formatted content. Also the urls should encoded as per the standards otherwise you may get errors from social media sites.
Ok, Lets check how we can change these share buttons details dynamically like many websites, shopping cart sites have different product images on a single page. So changing those images via Ajax will not work with normal share buttons(This will read only open graph or given urls data). This case you can use this method.
var share_url = "your url to share" ;
var share_image = "your image to share";
//full url not ../images should be http://www.
var title = "title";
var description = "description";
//title and description should be formatted ie, remove all special char otherwise it may creates errors on social media sites.
var FB_url = "http://www.facebook.com/sharer.php?s=100&p[title]="+(title)+"&p[summary]="+description+"&p[url]="+encodeURIComponent(share_url)+"&p[images][0]="+(share_image);
var GP_url = "https://plus.google.com/share?url="+encodeURIComponent(share_url);
var TW_url = "http://twitter.com/home?status="+escape(title)+"+"+encodeURIComponent(share_url);
var Pt_url = "http://pinterest.com/pin/create/bookmarklet/?media="+encodeURIComponent(share_image)+"&url="+encodeURIComponent(share_url)+"& is_video=false&description="+description;
var TB_url = "http://www.tumblr.com/share/photo?source="+encodeURIComponent(share_image)+"&caption="+(description)+"&clickthru="+encodeURIComponent(share_url);
var LK_url = "http://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(share_url)+"&title="+(title)+"&source="+encodeURIComponent(siteurl);
jQuery("#ref_fb").attr('href',FB_url);
jQuery("#ref_gp").attr('href',GP_url);
jQuery("#ref_tw").attr('href',TW_url);
jQuery("#ref_pr").attr('href',Pt_url);
jQuery("#ref_tum").attr('href',TB_url);
jQuery("#ref_lkd").attr('href',LK_url);
Make sure you page must includes any jQuery library.
While dynamically sending data through the social media sites using custom social share buttons the Google plus will not take image and other info, it required url to parse.
Hope this article will help you guys to fix the dynamically changing content sharing on social media with custom social share buttons.
22 thoughts on “Custom Social Share Buttons Integration”
How to share multiple images to social media….
This method is aimed for sharing exact image to the social media so it should be one image only.
If you’re preferring more than one image you have to use the traditional way of OG:IMAGE tags.
Hope it make sense.
Hello,
I’m looking to add a love button like the one on this website:
demo[dot]colorlabsproject[dot]com/photogram/
It would be great if you could tell me how should I go about in getting this or at least what exactly this is called so that I can search for ways of getting it.
Thanks in advance.
Simply use the image inside each
< a >
.Thanks for sharing your thoughts about custom social share buttons.
Awesome!! all of the code is working for me…
Thank’s man..
I am sure this article has touched all the internet
viewers, its really really nice article on building up new blog.
Thanks for finally writing about > Custom Social Share Buttons Integration –
| A Technical Blog Related to Open Source Scripting < Liked it!
it seems to retrieve empty data when in mobile specifically, iphone “safari” and samsung note “internet”… Can someone help?
The script have no specification for web/mobile it just simple JavaScript and open it in new window.
make sure the integration works in web perfectly, then it should work on mobile too, keep getting same result try to remove open with new window concept and use some call back technique.
Hope it helps.
Thanks for the reply!
yes, supposedly it would work because I only followed your code to all. It can share to almost all– chrome, FF, ie, ipad.. but except samsung note, iphone.. It seems like it havent retrieved the og data well..
See screenshot:
http://awesomescreenshot.com/0b42rzouae
Below is the code that works in desktop, ipad, but NOT iphone, samsung note:
My code are just all the same with yours above… It seems to work in desktop, and ipad.. but in iPhone and samusung note, it returns empty…
This is how it will look on some mobile device…
Please see the screenshot when viewd in iphone: http://awesomescreenshot.com/0472s92m27
Appreciate all the help!
I am trying to insert the facebook share code into a wordpress blog. I have put in a custom button and everthing works fine, only when i hit the button, the popup share window opens but it remains blank. i thought it would pull info from the post? here is the code, what am i doing wrong? thanks, steve
——————
Yes FB changed their concept , Please check my another post related to this topic,
http://www.walkswithme.net/facebook-share-button-with-custom-parameters.
Also codes will not be able to post on the comment box due to security reason, you can use the contact form for that purpose.
This is incredible, thanks!
You are welcome..
And this captcha… took me 10mins to post a reply, i cant believe it..
I will check and fix the issue,
thanks..
While it show’s the right data in Facebook’s sharing window, the actual shared data is totally different and it show’s clear that fb is reading the site and searching his meta tags when you click “Share”, and when its done, he replaces prepared content with hes own.
This is not working.
Sorry for the delayed reply,
Yes FB changed their concept , Please check my another post related to this topic,
http://www.walkswithme.net/facebook-share-button-with-custom-parameters
I want to say how to show only one image in google plus share button when i click g+ button it show multi images but i want to show only one image so please tell me how to customize g+ for only one image.
You cannot make that way bcoz Google reading your page url and parsing it all images. So by default it will show all the images.
Only one thing you can do, set a preferred image from the list of images on the page with the help of og:image tag. set the og:image tag with preferred image then you can see that image is selected by default while sharing on Google.
Thanks for your response..