Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

David Klotz
David Klotz
19,659 Points

stop video from playing when modal is closed

I have an iframe video in a modal that I am able to stop when the modal closes in an html document, however when I try to accomplish the same thing with the same code in WordPress, it continues to play. I have an iframe with the id="video" and a modal with the id="videoModal".

The script I'm using is :

$(function() {
    $('#videoModal').on('shown.bs.modal', function(e) {
        var src = $('#video').attr('data-iframe-src');
        $('#video').attr('src', src);
    });

    $('#videoModal').on('hidden.bs.modal', function(e) {
        $('#video').attr('src', '');
    });
});

For WordPress, I enqueued it with:

wp_enqueue_script( 'videomodal_js', get_template_directory_uri() . '/video-modal/js/videomodal.js', array('jquery', 'bootstrap_js'), '', true );

in my videomodal.js file, I tried leaving as is, and changing to jQuery(function($) and that didn't work either. I can't for the life of me figure out why it won't work in WordPress.