I'm loading (paging) posts with ajax, so I want to be able to render videos using MediaElement.js on newly appended content.

I already have my script working but is failing if no video posts are included on the initial page.

I imagine that if I enqueue the appropriate scripts on the blog pages is_home(), is_archive(), is_tag() then it will work even if no posts with videos are on the initial page.

Currently I'm trying this already got rid of the js error undefined mediaelement() but still videos are not rendering properly.

add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\pmt_mejs');
function pmt_mejs() {
    if ( !is_admin() ) {
        if ( is_home() || is_archive() || is_tag() ) {
            wp_enqueue_script( 'mediaelement' );
            wp_enqueue_script( 'wp-mediaelement' );

Haven't found any resources out there in the wild, any help would be really appreciated.

  • Just make sure it's enqueued on the page that's actually firing the AJAX - can you see it when you view source? Commented Aug 26, 2015 at 13:29

1 Answer 1


I had the same issue, but with the audio player.

First of all, you need enqueue MediaElement styles

wp_enqueue_style( 'wp-mediaelement' );

Next you need to add wp-mediaelement as dependency of your app script or enqueue it.



wp_enqueue_script( 'app', get_stylesheet_directory_uri() . '/js/app.js', array( 'jquery', 'wp-mediaelement' ));

As result you need something like that:

function my_enqueue_scripts(){
    wp_enqueue_style( 'wp-mediaelement' );
    wp_enqueue_script( 'app', get_stylesheet_directory_uri() . '/js/app.js', array( 'jquery', 'wp-mediaelement' ));

add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.