Created
March 22, 2012 18:39
-
-
Save micahwave/2161421 to your computer and use it in GitHub Desktop.
bitly shortlink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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