Skip to content

Instantly share code, notes, and snippets.

@theukedge
Created July 20, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theukedge/a274b7dd05e6ec2343ef to your computer and use it in GitHub Desktop.
Save theukedge/a274b7dd05e6ec2343ef to your computer and use it in GitHub Desktop.
<?php
// Enable the plugin only when Jetpack and Sharedaddy are enabled
function shortlinks_for_sharing_buttons() {
if (
class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'sharedaddy', Jetpack::get_active_modules() )
) {
add_filter( 'sharing_permalink', 'get_shortlink_for_post' );
}
}
add_action( 'plugins_loaded', 'shortlinks_for_sharing_buttons' );
// Grab the shortlink
function get_shortlink_for_post( $post ) {
global $post;
if ( !$post )
return;
$post_id = $post->ID;
if( function_exists( 'get_yourls_shortlink' ) ) {
if( get_yourls_shortlink() ) {
return get_yourls_shortlink( $post_id );
} else {
return get_permalink( $post_id );
}
} else {
return get_permalink( $post_id );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment