H5P Default Dynamic Sizing

H5P embed advanced options showing the dynamic sizing script option.

If you’re running the H5P plugin in WordPress, you might notice that there’s an advanced settings option when you go to embed it. If you click on that you’ll see an additional script to add to enable dynamic sizing of embedded H5P content. I wanted that but that option doesn’t make much sense in our environment.

H5P embed advanced options showing the dynamic sizing script option.

If you read this blog a lot and have an amazing memory, you’ll know I have a plugin that’s network activated where I put little things that make sense but don’t need their own dedicated plugin. This seemed like one that fits that bill.

It’s really simple. It asks if the site is running H5P and if the answer is yes, it enqueues the h5p-resizer.js.

/*------------------------------------H5P  ---------------------------------------------------*/
// Make H5P embeds flexible
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

if ( is_plugin_active(  'h5p/h5p.php' ) ) {
  //plugin is activated    
     add_action('wp_enqueue_scripts', 'h5pflex_widget_enqueue_script');
} 


function h5pflex_widget_enqueue_script() {   
    $h5p_script = plugins_url( 'h5p-resizer.js', __FILE__);
    wp_enqueue_script( 'h5p_flex', $h5p_script, true );
    }