I'm creating a wordpress theme. When I load the content using ajax it doesn't apply MediaElements.js to my audio player, so the audio isn't display. I think this is because the MediaElement.js is loaded with wp-footer(), and this new audio is added to the DOM after, and it's not recognized for MediaElement.js.
The same happend with local videos.
How can I resolve this?
I have found that this solves most cases:
You first need to make sure the mediaelement.js scripts are being loaded on all pages (ie even the ones that don't contain media).
functions.php (or similar)
Then it should simply be a case of calling this in your JS once your AJAX content has been injected to the page
main.js (or wherever)
You need to reinstantiate the
MediaElement
object on your newly appended elements.Alternatively, you can use an
Observer
to watch and apply.