Adding Shortlinks to Wordpress Tweet Button Through Jetpack plugin

[maj update=”02/08/12″]Totally got Jossed, now the Twitter links look worse than ever. Hopefully they fix that in the next update. Sorries!

This is the old way to fix your posts.[/maj]

Okay, so I changed up my Twitter button on Jetpack so I could use a short link and add “Via HarperKingsley0” my Twitter name. Took me about two minutes once I found out what I needed to do.

Go to Plugins => Installed Plugins => Jetpack => Edit => modules/sharedaddy.php => sharing-service.php. It should look like this “jetpack/modules/sharedaddy/sharing-service.php.”

Just click the code and run a Find for “Twitter” then scroll down until you find the code you need to change. Replace the “get_permalink” with “wpme_get_shortlink” and add “via=USERNAME&” after the frame address. Like this:

<iframe allowtransparency=”true” frameborder=”0″ scrolling=”no” src=”http://platform.twitter.com/widgets/tweet_button.html?via=HarperKingsley0&amp;url=’ . rawurlencode( apply_filters( ‘sharing_permalink’, wpme_get_shortlink( $post->ID ), $post->ID, $this->id ) ) . ‘&amp;counturl=’ . rawurlencode( str_replace( ‘https://’, ‘http://’, wpme_get_shortlink( $post->ID ) ) ) . ‘&amp;count=horizontal&amp;text=’ . rawurlencode( apply_filters( ‘sharing_post_title’, $post->post_title, $post->ID, $this->id ) ) . ‘: ” style=”width:97px; height:20px;”></iframe></div>’;
else
return $this->get_link( wpme_get_shortlink( $post->ID ), _x( ‘Twitter’, ‘share to’, ‘jetpack’ ), __( ‘Click to share on Twitter’, ‘jetpack’ ), ‘share=twitter’ );
}

public function process_request( $post, array $post_data ) {
$post_title = apply_filters( ‘sharing_post_title’, $post->post_title, $post->ID, $this->id );
$post_link = apply_filters( ‘sharing_permalink’, get_permalink( $post->ID ), $post->ID, $this->id );

The only problem is that I don’t think my Tweet numbers are showing up correctly. Anyone know how to fix it and keep my short link and Twitter showing?

[ Found the Twitter user name info at Gregory A McMullen’s site and the short link info at Skip’s Stuff. I discovered both through a Google search; I have no affiliation with either. ]

[maj update=”02/08/12″]Here’s the way the Jetpack code’s been changed. Anyone know a viable workaround? I still want to use my short link and now my Via is automagically screwed up (I’m on default mode right now and the via installed is supposed to be my blog, but it looks weird.):

function sharing_twitter_via( $post ) {
// Default ‘via’ is always us.
$via = preg_replace( ‘/(https?:\/\/)|(\.)|(\/)/i’, ”, home_url() );

// Allow themes to customize the via
return apply_filters( ‘sharing_twitter_via’, $via, $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><iframe allowtransparency=”true” frameborder=”0″ scrolling=”no” src=”‘ . esc_url( ‘http://platform.twitter.com/widgets/tweet_button.html?via=HarperKingsley0&amp;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 process_request( $post, array $post_data ) {
$post_title = $post->post_title;
$post_link = apply_filters( ‘sharing_permalink’, get_permalink( $post->ID ), $post->ID, $this->id );

if ( function_exists( ‘mb_stripos’ ) ) {
$strlen = ‘mb_strlen’;
$substr = ‘mb_substr’;
} else {
$strlen = ‘strlen’;
$substr = ‘substr’;
}

$via = $this->sharing_twitter_via( $post );
if ( $via ) {
$related = false;
$sig     = ” via @$via”;
} else {
$via     = false;
$related = false;
$sig     = ”;
}[/maj]

Leave a Reply


Patreon: HarperKingsley