JSON API + wordpress URL -
I am using a small JSON API for the URL shortener, which I would like to integrate on all my WordPress pages.
I know how to present the WordPress page URL, but what I do not know (due to no experience with API), how to present API results on WordPress page.
API Call:
http://abc.net/api?api=123&url=LONGURL The API here The result is:
{"error": "0", "abridged": "http://abc.net/ALIAS",} Here's the WP URL that needs to replace "LONGURL" above:
- Text "itemprop =" text ">
value Take that allow_url_fopen to true in php.ini function get_short_permalink () {$ permalink = get_permalink (); $ Response = file_get_contents ('http://abc.net/api?api=123&url='. Permalink); $ response = json_decode ($ response, true); if ($ response ['error'] == 0) Returns $ [['Brief'];} Return $ permalink;} Then replace and with & lt ;? php echo get_short_permalink ();? & Gt; in your template What this function does:
- Receives the original paramount
- sends a GET request for you
- Changes the response to a PHP array with a JSON string (
bool $ assoc
If you do not have error code 0 , or the original link, then you have to work together if you type in Url_fopen can not be enabled (or do not want to). In addition, a lot of things can be easier in WordPress: wp_remote_get
Comments
Post a Comment