Created
January 24, 2010 11:43
-
-
Save Uninen/285164 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
function print_lyhfi_url() { | |
/* | |
Example code for using Lyh.fi URLs in WordPress template code, inspired by | |
http://devmoose.com/coding/automatically-create-a-bitly-url-for-wordpress-posts | |
Disclaimer: This code is *NOT TESTED* with WordPress. | |
Lyh.fi API has currently no authentication nor versioning. It expects one | |
'url' parameter (GET) and it outputs data as JSON. Result looks like | |
{"shortUrl": "http://lyh.fi/B"} | |
Put following code in your WP-template to print shortened URL for a post: | |
<?php print_lyhfi_url(); ?> | |
PS. Please don't abuse the API -- use caching whenever possible. Thanks! | |
(c) 2010, Syneus Solutions, Ville Säävuori <[email protected]> | |
*/ | |
$url = get_permalink(); | |
$lyhfi_api_url = 'http://lyh.fi/api/?url='.urlencode($url); | |
$response = file_get_contents($lyhfi_api_url); | |
$json = @json_decode($response, true); | |
echo $json['shortUrl']; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment