Created
January 26, 2013 18:18
-
-
Save jeherve/4643624 to your computer and use it in GitHub Desktop.
[Jetpack] Use shortlinks instead of permalinks in sharing buttons http://i.wpne.ws/2H081K2L3Q0u
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 | |
/* | |
* Plugin Name: Jetpack shortlinks for sharing buttons | |
* Plugin URI: http://wordpress.org/extend/plugins/jetpack/ | |
* Description: Uses shortlinks instead of the permalink in sharing buttons | |
* Author: Jeremy Herve | |
* Version: 1.0 | |
* Author URI: http://jeremyherve.com | |
* License: GPL2+ | |
*/ | |
// Grab the shortlink | |
function jp_sd_custshortlink( $post ) { | |
global $post; | |
if ( !$post ) | |
return; | |
$post_id = $post->ID; | |
return wp_get_shortlink( $post_id ); | |
} | |
// Enable the plugin only when Jetpack and Sharedaddy are enabled | |
function jp_sd_custshortlink_enable() { | |
if ( | |
class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'sharedaddy', Jetpack::get_active_modules() ) | |
) { | |
add_filter( 'sharing_permalink', 'jp_sd_custshortlink' ); | |
} | |
} | |
add_action( 'plugins_loaded', 'jp_sd_custshortlink_enable' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment