Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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