Darek Kay's picture Darek Kay

Embed YouTube HD videos in Wordpress

As of 24.10.2019, YouTube no longer supports functions for setting or retrieving playback quality.

Wordpress supports auto-embeds: certain links are automatically converted into embed widgets. Embedding YouTube videos is done by pasting the URL. Unfortunately the video quality is low by default. It's possible to specify the quality using the vq parameter. Auto-embeds don't support parameters, though. There is a way to manipulate the generated html code by adding parameters to each embedded YouTube video automatically.

Add the following code to functions.php in your theme folder:

/* Play YouTube videos in the best quality available. */
function oembed_hd( $html, $url, $attr, $post_id ) {
if ( strpos ( $html, 'feature=oembed' ) !== false )
return str_replace( 'feature=oembed',
'feature=oembed&rel=0&vq=hd1080', $html );
return $html;
add_filter('embed_oembed_html', 'oembed_hd', 10, 4 );

The parameters explained:

  • rel=0 — Hides related videos.
  • vq=hd1080 — Forces a 1080p quality. Uses the best quality, if 1080p is not available.

Want to leave a comment?

If you want to give me some feedback, please contact me via Twitter or email. 💌

Embed YouTube HD videos in Wordpress