Regardless of whether or not people actually use social share buttons (they don’t), having them is still commonplace on any live site. Being able to share dynamic page content in a click, theoretically aids users in sharing your content. Here is a short snippet on getting that information from the browser, and converting it into a usable link for three major social media sites.
Some Basic Triggers
Starting off we need the button markup, which you’re free to write however you please. All that’s necessary is the id’s on the wrapping of your button/element. I’m gonna keep everything as plain as possible for demo purposes, but feel free to style up the content any way you wish.
Note that being an anchor tag is not necessary.
Include The Script
This script I put together by taking the URL of my desired outcome (available on each sites dev pages), and swapping out the information I wanted to be dynamic with variables.
Coming up with this in the end. All you need to do for your own use is swap out my @handle in the twitter link.
Your buttons will now be linked to share pertanent information about the current page. Great for blogs letting you automatically pull in a post excerpt or featured image, however there’s a good chance you may not want this running on every page.
I first made this for use with a wordpress site, where I wanted only posts to have these buttons. A quick solution to checking for this was the following…