Social media links can help a site gain a following. They can allow people to share pages and follow your social media pages. There are several plugins that can add links for you and they can work quite well. The problem is that these plugins hook your page into a third party application. I wouldn’t have too much trouble with this on its own. These applications seemed quite well put together. Then I found that my page load speed was increasing by an average of 3-4 seconds!
Thus I began a quest to figure out how to add social media links without plugins. I decided to have two places for social media links. The first at the end of each post, allowing users to share pages. The second would be links to follow my Twitter, Facebook and Google+ pages. These would appear in the sidebar.
The simplest way to add twitter buttons can be found on their website. It’s as simple as selecting the type of button you want and copy/pasting the code.
I wanted to have a vertical follow button like I was using for the others. There was no option for styling the button on the page. After a brief search I found this page. Here it lists a bunch of options for changing the style of the button.
Twitter code requires a URL. Each page and post in your website has a different URL so it’s not ideal to add one for each by hand. Fortunately you can replace the link with a WordPress function. If you look at the code provided you find it has something like
data-url="http://www.your-link-here.com/subpage". We can add a call to
get_permalink which provides the link to the current page.
The other thing you need to do is make sure that
data-via references your screen name. The final code for my share button looks like this: