Skip to content

Instantly share code, notes, and snippets.

@khromov
Created October 19, 2017 12:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khromov/36d5c1631346fea4dfe8222927798f9b to your computer and use it in GitHub Desktop.
Save khromov/36d5c1631346fea4dfe8222927798f9b to your computer and use it in GitHub Desktop.
Infogram oEmbed plugin
<?php
/*
Plugin Name: Infogram oEmbed
Plugin URI:
Description: Adds oEmbed support for infogr.am and infogram.com urls.
Author: khromov
Version: 1.0
Author URI: https://khromov.se
*/
wp_oembed_add_provider('https://infogr.am/*', 'https://infogr.am/oembed_iframe');
wp_oembed_add_provider('https://infogram.com/*', 'https://infogram.com/oembed_iframe');
add_action('wp_footer', function() {
?>
<script>
window.addEventListener('message', function(e) {
let data;
try {
data = JSON.parse(e.data);
} catch (e) {
return false;
}
if (data.context !== 'iframe.resize') {
return false;
}
let iframe = document.querySelector('iframe[src="' + data.src + '"]');
if (!iframe) {
return false;
}
iframe.height = data.height;
});
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment