The audio feature within WordPress allows you to embed audio files and play them back. This was added as of WordPress version 3.6.
WordPress included the feature as a shortcode which makes use of the markup I explained earlier. The shortcode will link to specific media file or files and output the HTML.
The default shortcode looks like this:
To link to your files you can declare the source of the files within the shortcode which would like like this:
You can also simply include a link to an audio file like below and WordPress will render it as audio and display a player.
This is my latest song
http://mywebsite/media/songs/sweetsong(.audioextension)
Some more content
To make sure your audio plays in all browsers you need to reference other types of audio for the same file like so:
Notice how the src""
attribute was dropped and new attributes were added. In this case it is mp3=" "
, ogg=" "
, wav=" "
.
Options for Playback.
The audio
shortcode allows for some options for playback.
src
The src
is an optional field but is wise to use especially if you have multiple browsers to support. The following types can be defined to allow for graceful fallbacks if a certain browser can’t render a specific audio type.
- mp3
- mp4
- ogg
- wav
- wma
loop
The option to automatically loop the playback of a file exists. By default this option is turned off. Personally if you loop audio playback I think you will just annoy your users so it may be best to avoid this all together.
or
autoplay
In very rare circumstances you may want to autoplay audio when a user visits a specific page. By default this option is turned off.
or
preload
You may want to preload audio in some circumstances. There are a few options available if you choose to do so:
-
– This is the default. The audio won’t load when the page loads but soon after.
-
– The audio loads along with the page.
-
– Only metadata loads when the page loads.