Created
May 22, 2020 13:05
-
-
Save mgibbs189/284c119dbbd243ccdfb66b812ebd8b9d to your computer and use it in GitHub Desktop.
FacetWP - layout builder - add MP3 URL into an HTML5 audio player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment