Social Share Buttons – 100 Days of Code Challenge

social sharing buttons

Social Share Buttons

Sharing and social media are like peanut butter and jelly. You can’t imagine one without the other. Thankfully the social media networks understand this. They make it pretty easy for someone with a little bit of tech know-how create ways to share content.

I ran into an issue at work and thought the challenge would be a good place try some things out.

The Wrong Way

First up, I have a confession to make. I will show you what happens when you rush to a solution without thinking through things fully. This PHP solution is way over complicated. It works, but a bit more thoughtfulness would have helped create a stand-alone file. Anyone implementing this solution has to have access to a machine running PHP. There is no reason for that.

I spent some time beating that up to let you know that even seasoned coders have to take a step back and understand their shortcomings. Too often we pop off saying something like, “It just needs to work.” There is truth in that sentiment. However, the end result should be something that is easily maintained. Here’s one of my most egregious errors.

Chaining Variable Assignments

I’m sure my intent was to come back and clean this up. How many of us have said that before? The empty string assignment is not all that bad. Someone may come through and see that as a handy way to save time, and not understand the consequences. Take the time to create and assign values. It isn’t even that much time.

The Reason You’re Here

I have confessed my sins as a programmer, and I feel better. Now let’s get into the what this thing actually works. First we get a chance to indicate which social networks we want to create social share buttons for. I started with Facebook, Twitter, LinkedIn, and Pinterest because those are the networks we interact with the most. Other networks can be added with a few additions. Also something that should have been thought about earlier in the process.

Secondly, we paste the URL to share. The full URL.

Thirdly, there are network specific bits of information that are needed to make working social share buttons. Forms are displayed for those networks.

Lastly, submitting the form generates working versions of the buttons along with the HTML code snippet needed.

social sharing buttons

Below is an example of LinkedIn’s share button.

linkedin social share buttons code

100 Days of Code Challenge

Today’s Progress:
  1. Made a single php page for social sharing buttons.

Thoughts I threw this together just trying to get something up. I over complicated it. I will simplify using separate css, javascript, and html files.

Link(s) to work

1.Shares

Check out my previous 100 Days of Code post.

You May Also Like