Adding @Username to Jetpack Sharedaddy

June 21st, 2012

Edit: Apparently, WordPress is being sticklers. When trying to update the code after a recent update, I tried both methods of adding my username to the tweet button. Only to find out neither work. For whatever reason, they are adamant about not allowing this to happen. Hopefully a solution will be worked out, because the API allows it.

It’s actually rather simple. However, it’s not technically just adding data-via=”USERNAME”. Unfortunately that doesn’t quite work right.

However, you can just add your username to the text inside of the Sharedaddy Module. Please note, I do not take any responsibility for broken code. I’m just giving you the potential for a work around.

You will want to edit this file: jetpack/modules/sharedaddy/sharing-sources.php – In this block of code.

return '
<div class="twitter_button"><iframe style="width: 97px; height: 20px;" src="http://platform.twitter.com/widgets/tweet_button.html?url='&lt;br /&gt;&lt;br /&gt; . rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post-&gt;ID ), $post-&gt;ID, $this-&gt;id ) )&lt;br /&gt;&lt;br /&gt; . '&amp;counturl='&lt;br /&gt;&lt;br /&gt; . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post-&gt;ID ) ) )&lt;br /&gt;&lt;br /&gt; . '&amp;count=horizontal&amp;text='&lt;br /&gt;&lt;br /&gt; . rawurlencode( apply_filters( 'sharing_post_title', $post-&gt;post_title, $post-&gt;ID, $this-&gt;id ) )&lt;br /&gt;&lt;br /&gt; . ': " frameborder="0" scrolling="no" width="320" height="240"></iframe></div>
';';

Simply Add your username (however you wish) after . '&count=horizontal&text='

I personally used:

. '&amp;count=horizontal&amp;text=Via @McMullen_Greg: '
. rawurlencode( apply_filters( 'sharing_post_title', $post-&gt;post_title, $post-&gt;ID, $this-&gt;id ) )
. ': " style="width:97px; height:20px;"&gt;

Which displays Via @McMullen_Greg: POST TITLE: URL

Not the greatest, but it does the job!

Edit: After tinkering around a little bit more, I figured out that Sharedaddy uses the Iframe version of the share button. You can easily add your usename by using query string parameters.

So instead of the above code use this.

<div class="twitter_button"><iframe style="width: 97px; height: 20px;" width="320" height="240"></iframe> src="http://platform.twitter.com/widgets/tweet_button.html?via=USERNAME&amp;url='
. rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post-&gt;ID ), $post-&gt;ID, $this-&gt;id ) )
. '&amp;counturl=' . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post-&gt;ID ) ) )
. '&amp;count=horizontal&amp;text='
. rawurlencode( apply_filters( 'sharing_post_title', $post-&gt;post_title, $post-&gt;ID, $this-&gt;id ) )
. ': " frameborder="0"
scrolling="no" width="320" height="240"&gt;</div>
&nbsp;

As you can see, we did use VIA=USERNAME instead of just adding to the text. With that, you can also add related, count or other properties as needed! Please ask if you have any questions.

Resources: Tweet Button Documentation | How to add a tweet button in wordpress with iframe code