Skip to main content

Add Custom Share Buttons to Blogger OR any website

Hello World,

In this post, I will be explaining on how to get those cool share buttons, which you see on the left of the screen. So straightaway here is my Javascript cum HTML for the same which is reusable without any tweak.



<script type="text/javascript">
 document.body.onload = getShareLink
 function getShareLink() {
  var url = window.location.href   
  document.getElementById("twi-tter").href = ["https://twitter.com/home?status=", encodeURIComponent(url)].join("")
  document.getElementById("face-book").href = ["https://www.facebook.com/sharer/sharer.php?u=", encodeURIComponent(url)].join("")
  document.getElementById("google-plus").href = ["https://plus.google.com/share?url=", encodeURIComponent(url)].join("")
  document.getElementById("linked-in").href = ["https://www.linkedin.com/shareArticle?mini=true&summary=&source=&url=", encodeURIComponent(url)].join("")
  document.getElementById("p-interest").href = ["https://pinterest.com/pin/create/button/?media=&description=&url=", encodeURIComponent(url)].join("")
 }
</script>
<div id= "shareButtonsContainer">
 <a style="text-decoration:none;" id="twi-tter" href="#" target="_blank">
  <img  style="display:inline; height:40px; width:40px" src="http://cdn2.hubspot.net/hub/53/file-954863050-png/00-MARKETING-OFFERS-hide-from-search/social-icons-01.png" alt="Share on Twitter" />
 </a>
 <a style="text-decoration:none;" id="face-book" href="#" target="_blank">
  <img style="display:inline; height:40px; width:40px" src="http://cdn2.hubspot.net/hub/53/file-953681786-png/social-icons-02-1.png" alt="social-icons-02-1" />
 </a>
 <a style="text-decoration:none;" id="google-plus" href="#" target="_blank">
  <img style="display:inline; height:40px; width:40px" src="http://cdn2.hubspot.net/hub/53/file-951108319-png/social-icons-05.png" alt="social-icons-05" />
 </a>
 <a style="text-decoration:none;" id="linked-in" href="#" target="_blank">
  <img style="display:inline; height:40px; width:40px" src="http://cdn2.hubspot.net/hub/53/file-951108339-png/social-icons-03-1.png" alt="social-icons-03-1" />
 </a>
 <a style="text-decoration:none;" id="p-interest" href="#" target="_blank">
  <img style="display:inline; height:40px; width:40px" src="http://cdn2.hubspot.net/hub/53/file-951108354-png/social-icons-04.png" alt="social-icons-04" />
 </a> 
</div>      
 

For blogger implementation, follow these steps :-
1. Go to Layout tab in the bloggers' Dashboard.

2. Click "Add a widget" on the right side bar. An extra window will open.
3. Select the HTML/Javascript widget. A text editor will show up.
4. Give a suitable title like "Share this Page".
5. Copy the above code and paste it into the big text area placed after the title Input box.
6. Click on Save Button and you are done.

In blogger, you can control the placement of the widgt, up down. But when you are implementing this code in a webpage other than blogger, you may have to do some extra CSS to place it where you want.

A little note on Javascript and how things are working in the HTML code :-
As you can see, I have added a bit of javascript in the script tag. It gets triggered just after the body loads during browser loads of the whole page. The getShareLink function is just amending the href attributes of the 5 <a> tags in the #shareButtonsContainer div, according to the current url of the webpage and each social media button. I have used www.sharelinkgenerator.com to generate the links.

Customizing Share button Icons :-
As you can see in the <img> tags, I am sourcing the image from some other website. You can pass you own url there. If you want to host your images on the google drive then here is a trick to make a permalink for the images in the Google Drive. Here are the steps :-
1. Upload an Image on Google drive.
2. Share it with Public and with viewing rights.
3. You will get a Url which would look like this.
https://drive.google.com/file/d/0BztaImknhgDFeXNQa1NnNWktQ1E/view?usp=sharing
4. The bold part in the above url is the ID. Copy that ID and use it to make a URL look like this:-
https://drive.google.com/uc?id=0BztaImknhgDFeXNQa1NnNWktQ1E
You can use this url as the src attribute of <img> tag for your Google Drive Images.
5. For resizing the images, you can change the height and width css attributes in the <img> tags. Currently its 40 X 40.

That is it for making you own share buttons. If you have any comments and suggestions, please comment below.

Thanks

Comments

  1. Filament
    In a single WordPress plugin, Filament contains a group of useful features including Flare, a social share button plugin that makes it easy for others to share your blogpost on Twitter, Facebook, Buffer, and more—even spots like Hacker News and Reddit. Other Filament apps include: MailChimp subscribe form, Google Analytics tracking, all-in-one profiles, code management, and share highlighter.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

Live Quotes Portfolio - Chrome Extension

Live Quotes Portfolio is a FREE Chrome Extension which keeps track of your stocks portfolio and also shows live stock quotes. It has so many other Features which I am gonna mention below :- Download from Chrome Webstore!! Note:- This post has been updated for changes. See Below for changes...   1. Keeps track of Number of shares bought at respective prices. 2. Shows Total Investment and Current Value of your portfolio with Return and percentage Return AND their Totals as well. 3. Besides current price, it also shows Daily Change and Daily Change Percentage. The above features are must in a portfolio app. Now its time for a really cool feature. What if your portfolio app takes your target and stoploss and notify you upon hit. Sound cool, isn't it ??

Alerty Web Browser Extension/Add-On

Wanna get Price Drop Alerts? or Wanna know when an Out of Stock Product will become available again? Well, let me present you with Alerty Web Extension for your browser. Alerty is a Browser Extension/Addon that can watch a list of products of your choice for Price Drops and Availability for free. Let me explain how it works. Installation Lets us start by installing the Alerty Extension/Addon on the browser. Open the Alerty installation page on the Extension/Add-On store for your Browsers. You can choose from the following links - 1. Chrome 2. Firefox 3. Edge 4. Brave 5. Opera Once you open the link, say in Chrome. Click 'Add to Chrome' button. It will install the extension. Add a Product Open the product listing, that you want to watch on Amazon/Flipkart and Hit the button in the Extension popup.