Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hello Guys,
Has anybody been able to get the couch instagram shortcode to work? I added the following code to the 'couch/addons/kfunctions.php' file :

Code: Select all
// Instagram shortcode
    // Example usage:
    //  [instagram BoGOAK_gLYq]
    $FUNCS->register_shortcode( 'instagram', 'instagram_handler' );
    function instagram_handler( $params, $content=null ){
        global $FUNCS;

        extract( $FUNCS->get_named_vars(array(
            'id' => '',
        ), $params) );

        $html = '';
        $id = trim( $id );
        if( strlen($id) ){
            $url = 'https://api.instagram.com/oembed/?url='.urlencode( 'https://www.instagram.com/p/'.$id );
            $res = $FUNCS->file_get_contents( $url );
            if( strlen($res) ){
                $res = $FUNCS->json_decode( $res );
                if( isset($res['html']) ){
                    $html = $res['html'];
                }
            }
        }

        return $html;
    }


and added the shortcode to my richtext textbox like so :
Code: Select all
[instagram BoGkRY3FBYv]
. At the front-end I wrapped the post content with the do_shortcode tag like this:
Code: Select all
<cms:do_shortcodes><cms:show news_content /></cms:do_shortcodes>
. However, this seems not to be working. When I inspect the code, it shows empty. Any reason why the shortcode is not working. I'm using CouchCMS Version 2.3
Empty means zero-length response from trying to access the url. Code in the shortcode is rudimentary and does not output anything if things go wrong. Try to see if the generated URL has any malice by outputting it
$url = 'https://api.instagram.com/oembed/?url='.urlencode( 'https://www.instagram.com/p/'.$id );

$html = $url;

$res = $FUNCS->file_get_contents( $url );

Then see if any response is coming from accessing that URL in browser. Let us know)
2 posts Page 1 of 1