ShareThis is a great sharing plugin built for WordPress that allows visitors to share your content through their own social media network with only a couple of easy clicks. The only complaints I’ve gotten from clients who use the plugin are:
- The buttons are aligned to the left rather than being centered on the line they occupy
- When their visitors share a post via Twitter, it doesn’t mention (@) their Twitter ID
Centering the Boxes
Rather than trying to modify the plugin code, you simply set your options and extract the code generated by the plugin to display the boxes. (Click on an image below to expand it to full size)
After following the instructions in the graphic illustrations above, open your theme’s editor (in the WordPress dashboard, go to Appearance –> Editor) then click on Single Post // single.php in the file list in the right side of the page. Find the tag and execute the following either above or below it depending on whether you want the buttons to be displayed above or below your content.
Paste the ShareThis code you copied from the plugin’s settings screen. Add <div style="text-align: center;">
to the beginning and add </div>
to the end of it.
Adding {@username} to Twitter Shares
Find the following section in the ShareThis code:
<span class='st_twitter_vcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span>
… replace that section with this and be sure to replace YOURusernameHERE with your Twitter ID:
<span class='st_twitter_vcount' st_title='<?php the_title(); ?> {via @YOURusernameHERE}' st_url='<?php the_permalink(); ?>' displayText='share'></span>
That’s it. You’ve got centered boxes and your visitors’ tweets sharing your content will mention you, or your brand’s, Twitter name. If you have any questions or complications, leave me a comment below!
Bonus: Add a share-to-Twitter link anywhere!
Add the following code to any of your theme files:
Using a text link:
<a href="http://twitter.com/home?status=Currently reading @YOURusernameHERE: <?php the_title(); ?> – <?php the_permalink(); ?>" title="Twitter">Share via Twitter!</a>
Using an image link:
<a href="http://twitter.com/home?status=Currently reading @YOURusernameHERE: <?php the_title(); ?> – <?php the_permalink(); ?>" title="Twitter"><img src="IMAGE SOURCE URL HERE"></a>
Thanks for the helpful advice. i need to know how to do this.
I could not make the @username adding work. It did not save and never showed up.
Did I miss something?
great help found in this article! adding @username to my twitter button on http://www.semsalabim.de/blog worked just fine. made my day :-)
I modified my ShareThis code for my WP blog by going to Settings >> ShareThis >> View/Modify HTML tags.
I changed my code to the following:
<span class='st_twitter' st_title=' via @ifelicious’ st_url=”
When I click on the Twitter icon for a blog post I see:
Blog Post Title via @ifelicious shortlink to post via @sharethis
How do I get the via @sharethis to drop off at the end?
How do I add my twitter username in this code? I have searched all over google with no luck:(
var switchTo5x=true;stBlogger2.init(“http://w.sharethis.com/button/buttons.js”, {“facebook”:[“hcount”,”Facebook”,””],”fblike”:[“hcount”,”Facebook Like”,””],”twitter”:[“hcount”,”Tweet”,””],”pinterest”:[“hcount”,”Pinterest”,””],”googleplus”:[“hcount”,”Google +”,””],”sharethis”:[“hcount”,”ShareThis”,””]} , “1d6c1abf-a8b9-4edc-ab3e-54e2ade9e3de”);var f = document.getElementById(“st_finder”);var c = f.parentNode.parentNode.childNodes;for (i=0;i<c.length;i++) { try { c[i].style.display = "none"; } catch (err) {}}
You need to leave ‘@’ out, type just the username… Well it used to work like this.
Now I’ve made a test tweet… I changed the things like I used to, but only after the test tweet. Now Twitter @name isn’t changing.
I flushed every cache, nothing.
Does anybody can confirm this on his end?
Maybe Sharethis changed its mind about it?
(if this isn’t working we won’t sick with Sharethis!)
I have the same question as the lady above! Please help!
Also, how do I change the “related” username?
Cool and nice plugin.