FacetWP – layout builder – add MP3 URL into an HTML5 audio player

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

// Add to your (child) theme’s functions.php
// Change “audio-mp3” to your layout builder’s item name (which defaults to “el-XXXXX”)

add_filter( ‘facetwp_builder_item_value’, function( $value, $item ) {
if ( ‘audio-mp3’ == $item[‘settings’][‘name’] && ! empty( $value ) ) {
ob_start();
?>
<audio controls>
<source src=”<?php echo $value; ?>” type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>
<?php
$value = ob_get_clean();
}
return $value;
}, 10, 2 );

{{/gist}}