Created
July 20, 2015 13:29
-
-
Save theukedge/a274b7dd05e6ec2343ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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