WordPress.org

Support

Support » Plugins and Hacks » Shares lost after URL redirect

Shares lost after URL redirect

  • This is not a problem with DiggDigg so much as a question on where in the code to make a change.

    After changing my permalink structure and putting 301 redirects in htaccess file, the share counters for DiggDigg are back to zero – the shares are only counted on the old URL obviously

    There are some posts on how to fix this, but I can’t find the place in the current DiggDigg code where I could put a universal fix for this to change the URL being sent to the social media sites for the share count.

    Any help would be appreciateed

    http://wordpress.org/plugins/digg-digg/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here’s a hack I made:

    function get_soderlind_permalink($permalink, $post, $leavename) {
      // Code from: http://encosia.com/preserving-social-sharing-counters-through-a-url-change/
      // Old permalink: /archives/%year%/%monthnum%/%day%/%postname%/
      // New permalink: /%postname%/
      //
      //  Changed URL structure from /archives/yyyy/mm/dd/slug to /slug on
      //  1/12/2013. This ensures older posts still present the old URLs
      //  to Digg Digg so that share counts are maintained.
      //  
    
    	// only run when get_permalink is called from dd_hook_wp_content
    	if ( function_exists('wp_debug_backtrace_summary') && stristr(wp_debug_backtrace_summary(), 'dd_hook_wp_content') !== FALSE) {
      		$url_change_date = strtotime( "12.1.2013" ); // use a date format strtotime understands. see notes at http://php.net/manual/en/function.strtotime.php
      		$post_date = strtotime( get_the_date( ) );
    		if ( $post_date < $url_change_date ) {
    			$url_date_prefix = sprintf("/archives/%s/%s/%s", date( "Y", $post_date ),  date( "m", $post_date ), date( "d", $post_date ));
    			$permalink = str_replace( site_url(), site_url() . $url_date_prefix, $permalink );
      		}
    	}
    	return $permalink;
    }
    add_filter( 'post_link','get_soderlind_permalink', 20, 3 )
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shares lost after URL redirect’ is closed to new replies.