2 edited tags
| link
1
source | link

Wordpress audio player causing js error, mediaelementplayer is not a function

I'm using the built in Wordpress audio player with my own skin, I needed to set the default volume to 100 so I put this into footer.php

<!--Change Wordpress Audio Player Default Volume-->
<script type="text/javascript">
jQuery(document).ready(function ($) {
    $("audio").mediaelementplayer({
        success: function (mediaElement, domObject) {
            mediaElement.setVolume(1.0);
        }
    });
});
</script>

Problem is I get the error Uncaught TypeError: $(...).mediaelementplayer is not a function on any page that doesn't have the [audio] shortcode because the wp-mediaelement.min.js and mediaelement-and-player.min.js JS files aren't loading on the pages without the shortcode, this in turn breaks other javascript on those pages.

What are my options here? Having the default volume at max is a must. Is my code written wrong?