1

I recently changed my permalink structure from /YYYY/MM/%post_name%/ to /%post_name%/, and lost my tweet counts and likes (provided by Jetpack) in the process.

To fix this, I want Jetpack to use the old-style permalinks for stories dated prior to the change. Unfortunately, it looks like I'll have to filter the content of get_permalink to do it.

So I have my function to return the fixed permalinks:

function jetpack_sharing_permalink( $permalink, $post, $leavename ) {

    $url_change_date = strtotime( "23 February 2013" ); // Date of the URL changeover
    $post_date = get_the_time( 'U', $post->ID );

    if ( $post_date < $url_change_date ) :
        $url_date_prefix = "/" . date( "Y", $post_date ) . "/" . date( "m", $post_date );
        $permalink = str_replace( get_site_url(), get_site_url() . $url_date_prefix, $permalink );
    endif;

    return $permalink;

}
  1. How do I use it to filter the output of get_permalink? Is my theme's functions.php too late?
  2. How would I get started writing a 'baby' plugin (as suggested) so that get_permalink is only filtered for Jetpack's Sharing feature?

Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.