Skip to content
JIX edited this page Jul 14, 2020 · 1 revision

Purpose

The Audio field builds on top of the File Field and allows users to select multiple audio files for a single player.

audio-field

When files have been selected, the field uses them as <src /> sub-tags for an audio tag. In the back-end, once files have been selected, an audio player preview is shown.

Settings

There are no additional settings for the audio field.

Usage

Using get_value to get the value of an audio field returns a boolean false when no files have been selected or an array with file IDs.

Using the_value will generate an HTML5 <audio> tag with all selected files as sources. This does not enqueue and scripts and styles automatically for the front-end.

<!-- Complete player -->
<?php the_value( 'song' ) ?>

<!-- Manual generation --?
<?php if( $files = get_value( 'song' ) ): ?>
<audio controls>
	<?php foreach( $files as $file ): ?>
		<source src="<?php echo wp_get_attachment_url( $file ) ?>" type="<?php echo get_post_mime_type( $file ) ?>" />
	<?php endforeach ?>
</audio>
<?php endif ?>
Clone this wiki locally