WordPress.org

Codex

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

Video Shortcode

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

[video]

You can also use built in embeds and simply put the media file on its own line:

  My cool content

  http://my.movies.com/cool/movie/coolest.mp4

  More cool content

Usage

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

[video]

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

[video src="video-source.mp4"]

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

[video mp4="source.mp4" ogv="source.ogv" webm="source.webm"]

Options

The following basic options are supported:

src
(string) (optional) The source of your video file. If not included it will auto-populate with the first video file attached to the post. You can use the following options to define specific filetypes, allowing for graceful fallbacks:
  • 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv'
Default: First video file attached to the post
poster
(string) (optional) Defines image to show as placeholder before the media plays.
Default: None
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 video should be loaded when the page loads. Defaults to "metadata".
  • "metadata" - ("default") only metadata should be loaded when the page loads
  • "none" - the video should not be loaded when the page loads
  • "auto" - the video should be loaded entirely when the page loads
Default: "metadata"
height
(integer) (required) Defines height of the media. Value is automatically detected on file upload.
Default: [Media file height]
width
(integer) (required) Defines width of the media. Value is automatically detected on file upload. Note that the theme's content_width sets the maximum width.
Default: [Media file width]

These options are also available in the video editor; once you've inserted a video in one of your posts, click on the video and then on the pencil icon to access and edit all the video details:

  • Video source file
  • Video alternate sources (mp4, ogv, webm)
  • Poster Image
  • Preload options
  • Tracks (subtitles, captions, descriptions, chapters, or metadata)

Source File

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

Related

WordPress Shortcodes: [audio], [caption], [embed], [gallery], [playlist], [video]