How to Add a Styled Google+, Facebook and Twitter Sharing to Your Blog in an Instant

by Jonny Rowntree

Social networking isn’t just great to meet and greet new people; it’s an essential tool for marketing and updating your readers on your latest and greatest content.

In order to make the direct link between your usage of social media to your blog back to your followers is to allow them to share your content with their followers.

How do you do that without employing a “social media marketer” and installing a bunch of deadly WordPress plugins?

Install an easy to use share menu within your blog using the Thesis Theme for WordPress.

All you need to do to achieve this is paste a few lines of pre-written code into your custom files and your content will start being shared like wild.

Step 1: Create the Function

Login into your WordPress admin and navigate to your Thesis admin panel. Click on the Custom File Editor and select custom_functions.php from the edit selected file menu.

Insert this code under your existing code, if you have any.

/* Share Menu */

function thesis_share() { if (is_single()) { ?>
    <ul class="share_menu">
        <li>
            <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="username">Tweet</a>
            <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
        </>
        <li>
            <iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=button_count&amp;show_faces=false&amp;
width=200&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; height: 20px; width: 100px"></iframe>
        </li>
        <li>
        	<g:plusone size="medium"></g:plusone>
        	<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
        </li>
    </ul>
<?php } }
    add_action('thesis_hook_before_post', 'thesis_share');

If you don’t have a Facebook page or account setup for your blog, you may want to consider deleting the Facebook like button from the code above. Additional share buttons can be added by visiting the relevant network as most have them.

If you want your @username on Twitter to be included every time people retweet your content, replace data-via=”username” with your own Twitter username.

Adding a Little Style

Now, switch to your custom.css stylesheet within your file editor.

Enter this code underneath any existing code. Adjust it to your liking and a share menu will appear before and after your post content.

/* Share Menu */

ul.share_menu { border-top: 1px solid #DDD; border-bottom: 1px solid #DDD; list-style: none; margin: 0 0 1em 0; padding: .6em 0 .2em 0; overflow: hidden }
	ul.share_menu li { float: left }

Once you have inserted these 2 snippets of code into the relevant files, the Thesis share menu is installed into your site. You no longer need to use those share plugins that slow down your site!

Jonny Rowntreeis a a 17 year old Web Designer and Snappy Blogger, who likes to create vibrant designs and travel a lot.

If you enjoyed this post, you’ll love the newsletter

Just enter your email below to get free updates:

{ 16 comments… read them below or add one }

Blogging Tips July 20, 2011 at 11:30 am

Hey when I add that code in the custom-functions.php , I get this error :

Parse error: syntax error, unexpected ‘}’ in /home/garish/public_html/wp-content/themes/thesis_182/custom/custom_functions.php on line 59

Any solution ?

Reply

Alex July 20, 2011 at 12:06 pm

Did you accidentally paste it within another function? It looks like there’s an issue with the curly brackets so you need to make sure you have closed them all.

Reply

Blogging Tips July 20, 2011 at 1:03 pm

I have pasted the code exactly as it is shown here and I have pasted it at the end in my custom-functions.php file. I don’t know which curly braces are you talking about (all are closed).

Reply

Markus July 20, 2011 at 11:59 am

Not working for me.

Reply

Alex July 20, 2011 at 12:06 pm

What’s the issue?

Reply

Avinash D'Souza July 20, 2011 at 1:20 pm

Hey Jonny,
Got a demo link as to what the finished output looks like?

Reply

Jonny Rowntree July 20, 2011 at 2:04 pm

Hi Avinash,

I’d check out Sushant’s link as it shows the end result perfectly! http://i55.tinypic.com/28m0iyv.png

Good luck with the install :)

Reply

Sushant July 20, 2011 at 1:32 pm

Worked fine for me. Just for the sake of testing, I implemented the code and here’s how it will appear on your blog…

Image: http://i55.tinypic.com/28m0iyv.png

Reply

Jonny Rowntree July 20, 2011 at 2:07 pm

Congrats! Thanks for the screenshot too. This will help a lot of others out!

Reply

Gunnar Engblom July 22, 2011 at 9:35 pm

Alex

I get the same problem as Blogging tips. I don’t know php so I just followed the instructions – and hoped for the best. Silly me!

“PHP Parse error: parse error, unexpected ‘{‘ in D:inetpubwwwrootkolibriexpeditions.comhtmlbirdingperublogwp-contentthemesthesis_15customcustom_functions.php on line 155″

Here is the code at the end where the problem should lie.. the previous from another online copy and paste instructions – that worked…..thanks in before hand..

}

}

/*
* this is where the magic happens, you attach your content to you theme
* by using thesis custom hooks
*
* if you want to turn off any of the messages, you can comment using ‘//’
* in front of any of those lines
*/

add_action(‘thesis_hook_before_post’, ‘social_welcome’);
add_action(‘thesis_hook_after_post’, ‘social_friendship’);

// end thesis customization for stumbleupon, digg and reddit

/* Share Menu */

function thesis_share() { if (is_single()) { ?>
    
        
            Tweet
            
        
        
            <iframe src="http://www.facebook.com/plugins/like.php?href=ID)); ?>&layout=button_count&show_faces=false&
width=200&action=like&colorscheme=light” scrolling=”no” frameborder=”0″ allowTransparency=”true” style=”border:none; overflow:hidden; height: 20px; width: 100px”>
        
        
            
            
        
    
<?php } }
    add_action('thesis_hook_before_post', 'thesis_share');
    add_action('thesis_hook_after_post', 'thesis_share');

Reply

Tinh July 23, 2011 at 1:41 am

Great tutorial :-) I am still using Digg Digg plugin to support this

Reply

Gregory C. August 11, 2011 at 7:09 pm

Got it working! I have to agree that some plugins like Digg Digg can take care of this more easily thought.

Reply

Anton Amoto November 4, 2011 at 8:14 am

Awesome post Jonny. I actually implemented this one on my blog. This is very useful to others who want to take advantage of adding social network sharing icons without using any wordpress plugins.

Reply

Jonny Rowntree November 4, 2011 at 8:20 am

Thanks Anton! Even though it is a simple tutorial, it is very powerful into targeting new traffic and makes your blog faster since you don’t need to use any WordPress plugins to use it!

Reply

Rurikxanðr November 12, 2011 at 5:06 pm

Excellent Tutorial Johnny! Kudos!

I would appreciate some input or feedback on how to setup a styled Google + icon on Thesis 18.

This will be for a site which does not use Facebook or Twitter.

Speed of loading is important so the fewer the number of WP plug-ins the better.

As I’m not familiar with.php or.CSS I have come up with this coding, please check it out:

/* Share Menu */

function thesis_share() { if (is_single()) { ?>

<?php } }

add_action('thesis_hook_before_post', 'thesis_share');

add_action('thesis_hook_after_post', 'thesis_share');

I'd like the Google+ icon to be similar in colour to Sushant's example.

My thanks to you all in advance,

Rurikxanðr

Reply

Raj | Make Money Blogging November 15, 2011 at 2:11 am

just added this code, for me it is appearing like this..

http://imageshack.us/photo/my-images/580/capturepxu.png/

what might be the error..?

Reply

Leave a Comment