This is an “add a social share button” Thesis Tutorial with a twist…
Here we’re not only going to add the official Facebook ‘share’ and Twitter buttons – we’re also going to include ‘Linkedin‘ and ‘Share by Email‘ buttons.
And all without a plug-in in sight!
And… we’re off!
Let’s add the following to your Thesis site…
- A ‘share by email’ button
- The official Facebook ‘Share’ Button (much better than the ‘like’ button)
- The official Linkedin Share button (yes, they do exist)
- The Official Twitter Button
Tools needed for today…
custom_funtions.phpcustom.css(these are in your ‘custom’ folder in Thesis)- 5 minutes of time
- This folder
(contains an image for you to upload as well as the following code for your reference)
Step One – Add a ‘Share by Email’ Image
Download and unzip the folder. Upload the email image into your thesis/custom/images folder.
Step Two – Back-Up (boring but important)
via ftp backup your custom_functions.php and custom.css files somewhere safe.
Personally, I never use the built in file editor (especially for custom_functions.php) for some reason stuff can go missing resulting in a broken site.
Step Three – Add The Share Button Codes into Custom_Functions.php
Copy and paste the following code into custom_functions.php and save to your server.
The only change you need to make to this code is on line 8. Replace ‘TWITTER USERNAME’ with your twitter username. e.g. mine is @richer_image so I would enter richer_image (without the ‘@’)
1 2 3 4 5 6 7 8 9 10 11 12 13 | function social_share_buttons() {
?>
<div class="share-buttons">
<ul>
<li><a href="mailto:?subject=Check this out&BODY=I found this article interesting and thought of sharing it with you. Check it out: <?php the_permalink(); ?>" target="_blank"></a></li>
<li><a name="fb_share"></a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></li>
<li><script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-url="<?php the_permalink(); ?>" data-counter="right"></script></li>
<li><a href="http://twitter.com/share" data-url="<?php the_permalink() ?>" data-text="<?php the_title(); ?>" data-count="horizontal" data-via="TWITTER USERNAME">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></li>
</ul>
</div>
<?php
}
add_action('thesis_hook_after_headline', 'social_share_buttons'); |
The actual positioning of these buttons is handled by thesis_hook_after_headline. You can change the position of your buttons by using an alternative Thesis hook such as thesis_hook_after_post.
For a full breakdown of all of the hooks available to Thesis, check out http://thesishooks.com/
of course you could add them to a couple of places simultaneously by using an additional hook like so…
13 14 | add_action('thesis_hook_after_headline', 'social_share_buttons'); add_action('thesis_hook_after_post', 'social_share_buttons'); |
This code will insert your share buttons site-wide – whether it be a blog post or a page. You can change what pages/posts the buttons are displayed on by using WordPress Conditional Tags.
For instance you can insert if ( is_single() ) { between lines 1 and 2 (not forgetting to add a additional closing bracket } to line 12) to make your buttons show only on single blog posts.
1 2 3 4 5 6 7 8 9 10 11 12 13 | function social_share_buttons() {
if (is_single()) {
<div class="share-buttons">
<ul>
<li><a href="mailto:?subject=Check this out&BODY=I found this article interesting and thought of sharing it with you. Check it out: <?php the_permalink(); ?>" target="_blank"></a></li>
<li><a name="fb_share"></a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></li>
<li><script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-url="<?php the_permalink(); ?>" data-counter="right"></script></li>
<li><a href="http://twitter.com/share" data-url="<?php the_permalink() ?>" data-text="<?php the_title(); ?>" data-count="horizontal" data-via="TWITTER USERNAME">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></li>
</ul>
</div>
<?php
} }
add_action('thesis_hook_after_headline', 'social_share_buttons'); |
Step Four – Let’s dress these puppies up with CSS…
Copy and paste the following into your custom.css file and save to your server.
1 2 3 4 5 6 7 8 | .custom .share-buttons ul {margin: 10px 0; display: inline-block;} .custom .share-buttons li {background: none !important; padding-left: 0 !important; list-style: none outside none !important; margin-right: 2px; vertical-align: top !important; display: inline-block; height: 19px !important; margin-bottom: 5px; } .custom .email-share a {background: url(images/email_icon_19x24.png) no-repeat scroll 0 0 transparent; display: block; height: 19px; margin: 0; width: 26px;} .custom .email-share a:hover {background-position: -26px 0;} .custom .email-share {margin-top: 0px;} .custom .facebook-share {margin-top: -4px;} .custom .linkedin-share {margin-top: -4px;} .custom .twitter-share {margin-top: 0px; margin-right: 0 !important;} |
Since each button is a slightly different size, the buttons do not ‘out-of-the-box’ sit horizontally well together. To address this, I’ve assigned each button it’s own class to enable targeted vertical and horizontal positioning by way of “margin styling” with CSS.
(I did look at using ‘vertical-align‘ but with no joy, if anyone knows of a better way to get them to align property I’d be pleased to know via the comments.)
And that’s it!
You should be up and running by now. This is my first ever Thesis Tutorial so I hope I got it right for you. Please let me know how you got on (good or bad) via the comment section – if you run into any problems I’ll do my best to help you out

{ 7 comments… read them below or add one }
Hi,
Thanks for this tutorial. I was just thinking about this today.
I do have one suggestion, though, which I was starting to research before I saw this post. Instead of using the permalink function, especially with Twitter, I suggest using the WordPress short link function
wp_get_shortlink().It’s not perfect, but it does make the link somewhat shorter. Perfect would be using the wp.me short link, which I think is only possible if you’re running the WordPress Stats plugin. And even then, I don’t know if they have a function for that you can access.
Anyhow, thanks again for your work.
Hi Bill, thanks for your comment. I did look at that but understand that twitter shortens all urls by default using it’s own service. I’ll check and get back to you.
Thanks again
Yep, twitter seems to shorten the url (t.co) prior to the opening of the ‘tweet’ window – so I’m guessing it doesn’t matter how your permalink is outputted.
It would be interesting though to see if it will still work with a permalink that exceeds the 140 characters initially, I know I’ve experienced this kind of problem before (think it was hootsuite).
Guess the only way to find out would be to do a really long headline for my next post!
Ah, I forgot about that. But I think you’re right, it doesn’t always work for some reason. I know I’ve had instances when it didn’t shorten a URL, but I never bothered to investigate further (because I use Hootsuite mostly). Thanks again.
Hi Richard
A few questions, though:
Thanks for the great tutorial! It was easily navigable even for a Thesis amateur like myself
1) On my blog, the Twitter button just shows up as the word “Tweet”; do you know why that might be?
2) On the main page, the three like buttons (for LinkedIn, Facebook and Twitter) only provide links to the blog’s opening page, and not to the post immediately above the buttons. Do you know how this might be remedied?
3) When you click on the Twitter button, the “share” function only provides a URL for the Tweet, not a headline or “via @NielsFootman”. Any idea how I could change that?
Apologies if some of the questions have very obvious answers, but I’d appreciate any help you could offer — even if it’s only pointing me in the direction of where I could fix these issues.
Many thanks
Niels
Hi Niels, thank you.
1. That’s how the official twitter button appears.
2. Ah! Something I haven’t noticed! Thank you for pointing it out. I’ve checked on mine and indeed that does happen with facebook and linked in (not with twitter) – I’m guessing this is because the link is physically on the homepage – granted this isn’t ideal – I’ll have a mooch for a fix.
3. Strange? That should work fine, you may want to paste in that line of code again in case anything weird happened (did you add in your user name without the ‘@’ as stated in Step 3?)
Thanks again Niels, please let me know how you get on.
Code updated with the Linkedin + homepage issue