WordPress: How to Get a Kaltura Video Widget to Render in Facebook Instant Articles

So in your posts you’re using the video widget from the Kaltura all in One Video Pack in tandem with the WordPress Instant Articles plugin.  You’re look at the debug information and you’re trying to understand why your videos aren’t showing up in the transformed markup.  This is because the video itself is not included in the source code of your post.  The widget works by inserting a few script tags in the markup which fire on page load and render your video player in an <iframe>.  So when the WordPress Instant Articles plugin transforms your markup the scripts haven’t fired and the video doesn’t exist in the markup yet.

 

If you’re like me you try playing with the transformer rules in the Instant Articles plugin’s settings to no avail.  Now you’re running out of time and you’re desperate.  Desperate times call for desperate measures.  Here is a function that overrides the Kaltura widget shortcode and replaces those script tags with an html5 video tag.

 


session->start($admin_secret, $user, KalturaSessionType::ADMIN, $partner_id);
if (!isset($ksession)) {
die("Could not establish Kaltura session. Please verify that you are using valid Kaltura partner credentials.");
}
//when creating the Kaltura Session it is important to specify that this KS should bypass entitlemets restrictions:

$api_url = ‘http://www.kaltura.com/api_v3/index.php?service=media&action=get&entryId=’;
$api_url .= $entryId;
$api_url .= ‘&ks=’;
$api_url .= $ksession;
$response = file_get_contents($api_url);
$response = new SimpleXMLElement($response);

$title = $response->result->name;
$description = $response->result->description;
$src_url = $response->result->dataUrl;
$thumb_url = $response->result->thumbnailUrl;
$html = ‘

‘;
$html .= ”;
$html .= ‘

‘;
$html .= $title;
$html .= ”;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= $title;
$html .= ‘

‘;
$html .= ”;
$html .= $description;
$html .= ‘

‘;
$html .= ‘

‘;

$html .= ‘

‘;

return $html;

}
add_shortcode( ‘kaltura-widget’, ‘kaltura_widget_func’ );

add_action( ‘wp_enqueue_scripts’, ‘load_dashicons_front_end’ );
function load_dashicons_front_end() {
wp_enqueue_style( ‘dashicons’ );
}

Filed in: Uncategorized

Philip Tadros - Founder
Philip Tadros is the Founder and CEO of Doejo an award winning Innovation Studio and INC 5,000 Company. Tadros also Founded and Manages Space by Doejo a Co-working loft in River North. Tadros was casted for ABC “Shark Tank” and featured on CNBC “Planet of the Apps” and a Moxie Award winner. Tadros’s ability to build and support strong, diverse teams with collaborative cultures, coupled with preference for innovation, has made him an authority on design and technology. He maintains positive and growing relationships with clients at Doejo with Companies like Pandora, Wilson and Groupon as well has helped Doejo be recognized globally as one of twelve WordPress VIP partners including one of the largest media companies, Tribune Media, ranked 45 on Comscore covering over half of the US market. Tadros’ ability to grow Companies has allowed for facilitating Construction, Development, Design as well as cohesively building talented Teams.