WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 );

    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.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.