Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created March 22, 2012 18:39
Show Gist options
  • Select an option

  • Save micahwave/2161421 to your computer and use it in GitHub Desktop.

Select an option

Save micahwave/2161421 to your computer and use it in GitHub Desktop.
bitly shortlink
/**
* Helper function to get the short url for a post
*
* @param int $post_id
* @return string $url
*/
function time_get_bitly_url( $post_id = null ) {
$post_id = empty( $post_id ) ? get_the_ID() : $post_id;
return get_post_meta( $post_id, 'time_bitly_url', true );
}
/**
* Filter to replace the default shortlink
*/
function time_bitly_shortlink( $shortlink, $id ) {
$bitly = time_get_bitly_url( $id );
if( $bitly ) $shortlink = esc_url( $bitly );
return $shortlink;
}
add_filter( 'pre_get_shortlink', 'time_bitly_shortlink', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment