Wordpress audio using wp_audio_shortcode

2019-08-21 00:33发布

问题:

I am using the latest Wordpress 4.9.6. I am trying to add some audio to one of my posts using the wp_audio_shortcode from my media-audio.php post format file.

I do manage to play the audio, but I do not really like the mejs-mediaelement player that somehow gets added. I actually want to completely remove this player and use the default code that appears:

<audio class="wp-audio-shortcode" id="audio-329-1" preload="none" style="width: 100%;" controls="controls"><source type="audio/mpeg" src="https://www.example.com/wp-content/uploads/2018/06/preview-1.m4a?_=1"><a href="https://www.example.com/wp-content/uploads/2018/06/preview-1.m4a">https://www.example.com/wp-content/uploads/2018/06/preview-1.m4a</a></audio>

How can I turn off/disable the mejs-mediaelement player that is added by the wp_audio_shortcode?

回答1:

How can I turn off/disable the mejs-mediaelement player that is added by the wp_audio_shortcode?

If you want to completely disable it, then use the wp_audio_shortcode_library hook to prevent the media / player library's CSS and JS files from being queued/loaded:

add_filter( 'wp_audio_shortcode_library', '__return_empty_string' );

Alternatively, don't disable the library, but disable or replace only the default CSS class name: (the default media library JS/script for the [audio] Shortcode is targeting only HTML elements with the wp-audio-shortcode class)

add_filter( 'wp_audio_shortcode_class', '__return_empty_string' );