WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Audio Shortcode

The Audio feature allows you to embed audio files and play them back using a simple Shortcode. This was added as of WordPress 3.6 and is used like this:

[audio]

You can also use build in embeds and simply put the media file on it's own line:

  My cool content

  http://my.mp3s.com/cool/songs/coolest.mp3

  More cool content

Practical Usage

I have an old post that has an audio file in the Media Library attached to it, and I want to use the new shortcode:

[audio]

I have the URL for an MP3, from the Media Library or external, that I want to play:

[audio src="audio-source.mp3"]

I have a source URL and fallbacks for other HTML5-supported filetypes:

[audio mp3="source.mp3" ogg="source.ogg" wav="source.wav"]

Options

The following basic options are supported:

src
(string) (optional) The source of your audio file. If not included it will auto-populate with the first audio file attached to the post. You can use the following options to define specific filetypes, allowing for graceful fallbacks:
  • 'mp3', 'm4a', 'ogg', 'wav', 'wma'
Default: First audio file attached to the post
loop
(string) (optional) Allows for the looping of media. Defaults to "off".
  • "off" - ("default") does not loop the media
  • "on" - media will loop to beginning when finished and automatically continue playing
Default: "off"
autoplay
(string) (optional) Causes the media to automatically play as soon as the media file is ready. Defaults to "off".
  • "off" - ("default") does not automatically play the media
  • "on" - Media will play as soon as the media is ready
Default: "off"
preload
(string) (optional) Specifies if and how the audio should be loaded when the page loads. Defaults to "none".
  • "none" - ("default") the audio should not be loaded when the page loads
  • "auto" - the audio should be loaded entirely when the page loads
  • "metadata" - only metadata should be loaded when the page loads
Default: "none"

Source File

The audio shortcode is located in wp-includes/media.php.