WordPress.org

Ready to get started?Download WordPress

Forums

Add "via @username" to Tweet button? Using JetPack for WordPress (23 posts)

  1. adg3724
    Member
    Posted 2 years ago #

    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.

  2. adg3724
    Member
    Posted 2 years ago #

    Any ideas JarretC? :)

  3. adg3724
    Member
    Posted 2 years ago #

    Sorry for the bump, I need it asap :)

  4. Greg McMullen
    Member
    Posted 2 years ago #

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

  5. Greg McMullen
    Member
    Posted 2 years ago #

    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.

  6. zackcello
    Member
    Posted 1 year ago #

    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!

  7. zackcello
    Member
    Posted 1 year ago #

    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

  8. Greg McMullen
    Member
    Posted 1 year ago #

    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!

  9. Greg McMullen
    Member
    Posted 1 year ago #

    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.

  10. zackcello
    Member
    Posted 1 year ago #

    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!

  11. olajideolaolorun
    Member
    Posted 1 year ago #

    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

  12. Greg McMullen
    Member
    Posted 1 year ago #

    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.

  13. olajideolaolorun
    Member
    Posted 1 year ago #

    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

  14. ruador
    Member
    Posted 1 year ago #

    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!

  15. olajideolaolorun
    Member
    Posted 1 year ago #

    Thanks ruador!
    Life saver. Lol

  16. jsandlund
    Member
    Posted 1 year ago #

    Strange. For some reason it doesn't work for me. @Ruador - did you have to edit files anywhere else?

    Best,
    JS

  17. zackcello
    Member
    Posted 1 year ago #

    Hey guys, I just switched to AddThis. These features are built in already, and it works way better than Jetpack's.

    Try it out!
    http://wordpress.org/extend/plugins/addthis/

  18. ruador
    Member
    Posted 1 year ago #

    No, I didn't change anything else jsandlund!

    It's just a about to add manually
    the part of the adress that uses twitter:

    https://twitter.com/intent/tweet?via=HERETHEUSERNAME&text=HERETHETITLE&url=HERETHEURL

  19. Spaice
    Member
    Posted 1 year ago #

    I found a workaround in line 331 of sharing-sources.php, i don't know how to do this through my theme though. Anyone know the answer?:

    Original:

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

    New (Twitter name where I have put "USERNAME" but no @ sign:

    function sharing_twitter_via( $post ) {
    		// Allow themes to customize the via
    		return apply_filters( 'jetpack_sharing_twitter_via', "USERNAME", $post->ID );
    	}
  20. Spaice
    Member
    Posted 1 year ago #

    Does anyone have a solution to the other part of the original post - i.e. shorterned url in the tweet? Can we somehow use the wp.me shortlink?

  21. Brooke Dukes
    Member
    Posted 1 year ago #

    I refuse to edit core plugin files unless absolutly nessary. There is another way to go about it by adding a new service with the via attributed added. Here is what I did:

    After revewing Twitters API for links I went to the sharing settings selected add new service, named it then added the link https://twitter.com/share?text=%post_title%&url=%post_url%&via=USERNAME

    For the icon I used the default sharedaddy one located at 'plugins/jetpack/modules/sharedaddy/images/twitter.png'

    This seems to work and shouldn't break with updates

  22. Keith
    Member
    Posted 1 year ago #

    Great find Bandon, worked like a champ.

  23. cwhebert
    Member
    Posted 1 year ago #

    FYI: The only problem with BrandonRandon's find is it won't show the count. If you are looking for a count you may have to hack the plugin code, which as mentioned, would be impacted when updating the plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic