Pass YOURLS short links to Jetpack’s Publicize and Sharing modules

I love the convenience of JetPack and all of the modules it brings to the table, including their Publicize and Sharing modules which create new posts on your social media accounts for new content and provide sharing buttons at the bottom of your content respectively.

I started using YOURLS earlier this year to take control of my own short URLs and I was instantly in love, so I kept it up. But there came a point where I wanted JetPack’s Publicize and Sharing modules to use these short URLs instead of the post’s permalink to capture the stats of where my readers where coming from.

Luckily, JetPack has lots of filters and hooks, so changing the URL used by these modules wasn’t too difficult. I dropped the following code into my functionality plugin and I was all set:

3 thoughts on “Pass YOURLS short links to Jetpack’s Publicize and Sharing modules”

  1. nicmare says:

    seems to work for sharing buttons only. thank you. but publicize still uses long permalinks. any ideas?

    1. You’re right. Publicize does not adhere to this and Jetpack has been petitioned to provide a filter for it.

  2. nicmare says:

    btw – have it shorter and smarter:
    if (class_exists( ‘Jetpack’ ) && Jetpack::is_module_active(‘sharedaddy’)) {
    function get_shortlink_for_post( $post ) {
    global $post;
    if ( !$post ) return;
    if( $shortlink = wp_get_shortlink( $post->ID ) ) return $shortlink;
    else {
    return get_permalink( $post->ID );
    add_filter( ‘sharing_permalink’, ‘get_shortlink_for_post’ );

Leave a Reply