I am trying to change some of the settings that get loaded with MediaElement.js. I can’t seem to find a filter or hook to alter the settings that are loaded. The only way I was able to customize the settings is by opening up the core MediaElement.js file and changing the settings there.
Obviously this is less than ideal, because I’m forced to edit a core WordPress file which will be overridden on update. How can I change the settings using a filter so my settings aren’t lost?
I am trying to set
enableKeyboard: false
Copy
wp-includes/js/mediaelement/wp-mediaelement.js
into your theme or plugin and make your modifications there. For example, I added some settings to force the use of native video controls on iOS & Android devices, like so:You can then use an action to dequeue the original and enqueue your modified version. If you’re doing this in a theme, add the following to your functions.php file:
This assumes you put your modified
wp-mediaelement.js
file inside ajs
directory within your theme.Since WordPress 4.4 there actually is the filter mejs_settings, which does exactly what you want.
In your case:
If anyone is interested, it works like this:
wp-includes/script-loader.php
turns this into an inline<script>
in the<head>
that sets a global JS object_wpmejsSettings
, which, ondomReady
, is passed to the.mediaelementplayer()
function inwp-includes/js/mediaelement/wp-mediaelement.js
.