WordPress.org

Support

Support » How-To and Troubleshooting » Add "via @username" to Tweet button? Using JetPack for WordPress

Add "via @username" to Tweet button? Using JetPack for WordPress

  • Hi all! Right now, when a reader clicks Tweet on my post, they see “Post name: Long URL” to share. How can I change that to “Post name | Shortened URL via @twittername”?

    I’m using JetPack’s social sharing service which I think uses ShareDaddy? Any help is appreciated.

Viewing 15 replies - 1 through 15 (of 22 total)
  • Any ideas JarretC? 🙂

    Sorry for the bump, I need it asap 🙂

    I’ve figured it out before, are you still looking for the answer?

    You will want to edit this file: jetpack/modules/sharedaddy/sharing-sources.php

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

    The tweet would then Read Via Username: TITLE OF THE POST: <URL>

    Hope this helps.

    I just tried this, and it didn’t work. The pop-up tweet still is missing my handle. Any chance the code should be different now that Jetpack has updated recently? Thank you so much for your help!

    PS I have 1.8.2 that just came out. And I would like to insert my username BEFORE both the title and the link. My site is: http://simplythreetrio.com

    I’ve tried using the iFrame settings (https://dev.twitter.com/discussions/3946) and just by adding the text and it seems as though Jetpack throws out the customizations.

    Sorry, but it seems like they are adamant about not letting us add usernames to the tweet button.

    If you want the button with your username I would either just add a Follow button at the top of your site, or manually put the buttons below your theme (they give you that option in the settings).

    This “setting” is truly an annoyance and I’m not sure why they are being so harsh about it.

    Cheers!

    Figured out a method. If you go to the Jetpack.me website and use their twitter button, it works. Don’t ask me why, but it does.

    Inside sharing-sources.php you’ll see that there is a function

    sharing_twitter_via( $post ) {
    // Allow themes to customize the via
    return apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID );
    }

    Well under that you’ll see

    public function get_display( $post ) {
    		$via = $this->sharing_twitter_via( $post );
    
    		if ( $via ) {
    			$via = '&via=' . rawurlencode( $via );
    
    			$related = $this->get_related_accounts( $post );
    			if ( ! empty( $related ) && $related !== $via )
    				$via .= '&related=' . rawurlencode( $related );
    		} else {
    			$via = '';
    		}

    I just added $via = "USERNAME"; and the code works and the button now pulls in the username.

    If I can figure out the theme option I will post that here as well.

    Awesome!! It works now! Now if I could just get the username before the title, and also if I could change the link to wp.me or bit.ly, it would be perfect. But this works for now! I really appreciate your help and lightning fast response!

    Kinda confusing. Doesnt work here.

    In the code…

    public function get_display( $post ) {
    		$via = $this->sharing_twitter_via( $post );
    
    		if ( $via ) {
    			$via = '&via=' . rawurlencode( $via );
    
    			$related = $this->get_related_accounts( $post );
    			if ( ! empty( $related ) && $related !== $via )
    				$via .= '&related=' . rawurlencode( $related );
    		} else {
    			$via = '';
    		}

    I tried….
    $via = ‘&via= @kingola’ . rawurlencode( $via );
    Also tried…
    $via = $this->sharing_twitter_via( $post ); into $via = “@kingola”;
    And even under else…
    $via = ‘@kingola’;

    Nothing works. I have 1.8.2

    Remove the @ and try again. It should work.

    Zack. The via function in the URL code from the API forces it at the end. I don’t know f a way to remedy that.

    I tried that, doesnt work.
    Can you please re-write the code here… cause i dont even know which option. I did it for everything i thought it might be and nothing.

    Thanks

    Hey!

    I was on the same thing.

    Finally I managed adding ?via=USERNAME after (replace USERNAME for your twitter username, without @)

    twitter.com/intent/tweet

    so it might look like

    twitter.com/intent/tweet?via=USERNAME

    the entire line is

    $twitter_url = add_query_arg(
    			urlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ),
    			sprintf( '%s://twitter.com/intent/tweet?via=USERNAME', ( is_ssl() ? 'https' : 'http' ) )
    		);

    It works!

    Thanks ruador!
    Life saver. Lol

    Strange. For some reason it doesn’t work for me. @ruador – did you have to edit files anywhere else?

    Best,
    JS

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Add "via @username" to Tweet button? Using JetPack for WordPress’ is closed to new replies.
Skip to toolbar