Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function yoast_bitly_shortlink($url, $id, $context, $allow_slugs) {
- if ( ( is_singular() && !is_preview() ) || $context == 'post' ) {
- $short = get_post_meta($id, '_yoast_bitlylink', true);
- if ( !$short || $short == '' ) {
- if ( !defined('BITLY_USERNAME') || !defined('BITLY_APIKEY') ) {
- $short = 'http://yoast.com/wordpress/bitly-shortlinks/configure-bitly/';
- } else {
- $url = get_permalink( $id );
- $resp = wp_remote_get('http://api.bit.ly/v3/shorten?format=txt&longUrl='.$url.'&login='.BITLY_USERNAME.'&apiKey='.BITLY_APIKEY);
- if (is_array($resp))
- if ( $resp['response']['code'] == 200 ) {
- $short = $resp['body'];
- update_post_meta( $id, '_yoast_bitlylink', $short);
- }
- }
- }
- return $short;
- }
- return false;
- }
- add_filter('pre_get_shortlink','yoast_bitly_shortlink',99,4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement