Useful Snippets

Welcome!


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at Unwanted.cloud

RSS Latest posts from my personal blog


Subscribe to RSS feed


Embed Infogram in WordPress

Stanislav KhromovStanislav Khromov

Here is a plugin to enable embeds for Infogram URLs. Simply paste the URL on your page and it will become an embed on your site.

<?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
});

Full-stack impostor syndrome sufferer & Software Engineer at Schibsted Media Group

Comments 0
There are currently no comments.