While YouTube does makes it simple to embed a video into your website, the method doesn't come without its disadvantages - styles and features are limited, scalability isn't enabled by default, and changing site-wide occurrences of video presentations is problematic. This article introduces a WordPress shortcode that'll permit you to include single videos and playlists into a post or page with ease via the use of WordPress shortcode.
The following video introduces the basic usage of the shortcode and WP Plugin.
YouTube Embed Examples
To embed a single video with shortcode, use
[youtube v="kVUy4i130iM"]. Virtually any YouTube URL is accepted; we'll fetch the video ID. That said, it's best practice to include only the video ID. The result is as follows:
To play only a selected portion of a video, simply define the start and end time in seconds as follows:
[youtube v="vbxl3hc_pL8" start="121" end="138"]. The result is as follows:
A number of options can be applied, and they're listed below as "shortcode attributes".
Display a YouTube Video Playlist
A playlist can be a user created playlist, the results of a search, or user uploads. Additionally, you can provide your own comma separated list of video ID values.
To display a user created playlist - in this case one from Flight's channel - we'll use
[youtube listtype="playlist" list="PLR6JWLm3S69cmRsglaYYGa7Jy0GDbsI44"]. The result:
In another example of a playlist, this time for a search term, we'll use . Search playlists are no longer supported.
[youtube listtype="search" list="space flight"]. The result:
Display a Custom Playlist
A custom playlist includes a comma seperated list of any video of your choosing. For example,
[youtube playlist="rE6a7uFJoss,Itjvfy2pBxA,NfQprOcjO3c"]. The result:
If a primary video is defined (as
youtube v="kVUy4i130iM playlist="rE6a7uFJoss,Itjvfy2pBxA,NfQprOcjO3c"], the defined video (in this case,
kVUy4i130iMM) will play before your playlist.
The following shortcode options are available. Many of the descriptions come from Google's player parameter page .
v, or video ID, is required. To an embed a basic video it's the only attribute that's required.
heightshould almost always be left blank. Rather, we have a HD (true/false) option below that'll automatically scale the video as required.
autoplay="1"the video will automatically play on page load. It's false by default.
hd="0". This attribute negates the need to specify a height.
startthe video at a certain point, use
start="75", where 75 is the number of seconds from the beginning of the video.
endthe video at a certain point, use
end="127", where 127 is the number of seconds from the beginning of the video.
listtypeattribute is used in company with the
listattribute below. The
listtypeshould be set to
user_uploads. The list below provides the value.
listparameter, in conjunction with the
listTypeparameter (above), identifies the content that will load in the player. If the
listTypeparameter value is
user_uploads, then the list parameter value identifies the YouTube channel whose uploaded videos will be loaded. If the
listTypeparameter value is
playlist, then the list parameter value specifies a YouTube playlist ID. If you specify values for the
listTypeparameters, you do not need to specify a video ID. Note that
searchis no longer supported.
[youtube playlist="rE6a7uFJoss,Itjvfy2pBxA,NfQprOcjO3c"]. They ID can be from any account and reference any video. If you also specify a video ID, that video will play first.
privacy="1"to use the
www.youtube-nocookie.comdomain. Usually not required.
modestbranding="0"in your shortcode to enable the logo, or alter the shortcode function to avoid repeatedly having to include it.
controlsindicates whether the video player controls are displayed. If
controls="0"no player controls will be shown. If
controls="1"the controls load on page load, and if
controls="2"the controls appear with user interaction. by default,
rel="1"or alter the shortcode function if you'd like this feature enabled for all embeds.
rel="1"in your shortcode now forces related videos from your own channel - generally preferred behaviour. Set to
rel="0"to show videos from any channel.
cc_load_policy="1"causes closed captions to be shown by default, even if the user has turned captions off. The default behavior is based on user preference. By default the value is 0 (false).
color="white"(this disables modest branding options).
disablekb="1"(the spacebar and arrows control playback).
fs="0". The feature is enabled by default.
Options not discussed include
playsinline. If you're looking for these features, you don't need us to explain them to you. More details on player parameter options are available here .
The Shortcode Function
It's always best to download the shortcode function rather than copy text. Alternatively, we've provided a WordPress plugin you can use like any other.
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin.
YouTube is heavily integrated into our Yabber Digital Marketing and Social Media platform. To set default behaviour for all videos globally, you may do so via the YouTube section of the Platform. In our case we simply store the default options and merge them with the
$atts array before returning a video.
This snipped is due for an update and will be replaced soon.