Skip to content

Instantly share code, notes, and snippets.

@Otto42
Last active December 22, 2015 16:49
Show Gist options
  • Select an option

  • Save Otto42/6502082 to your computer and use it in GitHub Desktop.

Select an option

Save Otto42/6502082 to your computer and use it in GitHub Desktop.
Instagram embed override code for WordPress, to use the embed iframe instead of Instagram's own oEmbed API endpoint.
<?php
/*
Plugin Name: Instagram Frame Embedder
Author: Otto
*/
wp_embed_register_handler( 'instagram', '#https?://instagr(\.am|am\.com)/p/([^/]+)#i', 'custom_embed_handler_instagram' );
function custom_embed_handler_instagram( $matches, $attr, $url, $rawattr ) {
if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
$width = (int) $rawattr['width'];
$height = (int) $rawattr['height'];
} else {
list( $width, $height ) = wp_expand_dimensions( 612, 710, $attr['width'], $attr['height'] );
}
return apply_filters( 'embed_instagram', "<iframe src='//instagram.com/p/". esc_attr($matches[2]). "/embed/' width='{$width}' height='{$height}' frameborder='0' scrolling='no' allowtransparency='true'></iframe>" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment