WordPress: wp.me shortlinks in tweets using Jetpack 1.6.1
Comments OffJuly 13, 2012 by Skip
If you’re using WordPress and Twitter you probably understand the magic of wp.me shortlinks within tweets. For those who don’t know, the links are parsed by Twitter and a preview of your post is shown inline. It’s a good thing. My question was how do I get the Jetpack Twitter sharing button to natively use the wp.me shortlink rather than the standard permalink. It was actually pretty easy.
- From the Dashboard, go to Installed Plugins and choose to Edit Jetpack.
- Choose the Plugin File ‘jetpack/modules/sharedaddy.php’
- Then ‘jetpack/modules/sharedaddy/sharing-sources.php’
- Search for the text ‘twitter_button’ and that should find this point in the file, but it won’t be formatted as well…
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | public function get_display( $post ) { $via = $this->sharing_twitter_via( $post ); if ( $via ) { $via = sprintf( '&via=%1$s', rawurlencode( $via ) ); } else { $via = ''; } if ( $this->smart ) { return '<div class="twitter_button"><iframe allowtransparency="true" frameborder="0" scrolling="no" src="' . esc_url( '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=' . rawurlencode( $post->post_title . ':' ) . $via ) . '" style="width:101px; height:20px;"></iframe></div>'; } else { if ( 'icon-text' == $this->button_style || 'text' == $this->button_style ) sharing_register_post_for_share_counts( $post->ID ); return $this->get_link( get_permalink( $post->ID ), _x( 'Twitter', 'share to', 'jetpack' ), __( 'Click to share on Twitter', 'jetpack' ), 'share=twitter', 'sharing-twitter-' . $post->ID ); } } |
public function get_display( $post ) {
$via = $this->sharing_twitter_via( $post );
if ( $via ) {
$via = sprintf( '&via=%1$s', rawurlencode( $via ) );
} else {
$via = '';
}
if ( $this->smart ) {
return '<div class="twitter_button"><iframe allowtransparency="true" frameborder="0" scrolling="no" src="' . esc_url( '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=' . rawurlencode( $post->post_title . ':' ) . $via ) . '" style="width:101px; height:20px;"></iframe></div>';
} else {
if ( 'icon-text' == $this->button_style || 'text' == $this->button_style )
sharing_register_post_for_share_counts( $post->ID );
return $this->get_link( get_permalink( $post->ID ), _x( 'Twitter', 'share to', 'jetpack' ), __( 'Click to share on Twitter', 'jetpack' ), 'share=twitter', 'sharing-twitter-' . $post->ID );
}
}- Within lines 344 & 348 are three instances of ‘get_permalink’, replace those with ‘wpme_get_shortlink’.
- Choose ‘Update File’ and you should be good to go.
Now any use of the Twitter sharing button will default to the wp.me shortlinks.
This will also surely work with the other sharing services as well, but I haven’t seen the need to experiment in that direction. Also different versions of Jetpack should be the same, but line numbers and exact context will probably differ.
Hope that helps!
UPDATE: This was originally written for Jetpack 1.4.2 and with the release of 1.5 all steps including line numbers remained unchanged.
UPDATE: 08-03-2012 Jetpack 1.6.1 released. Instructions remain the same except line numbers have changed. Previous to 1.6.1 line numbers were 262 & 264. Now same changes are made in lines 344 & 348.
Category Resources | Tags: Jetpack, Shortlinks, Twitter, Wordpress, wp.me
Comments Off
Sorry, comments are closed.



Comments