Last active
December 22, 2015 16:49
-
-
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.
This file contains hidden or 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 | |
| /* | |
| 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