wp_embed_handler_youtube( array $matches, array $attr, string $url, array $rawattr ): string

YouTube iframe embed handler callback.

Description

Catches YouTube iframe embed URLs that are not parsable by oEmbed but can be translated into a URL that is.

Parameters

$matchesarrayrequired
The RegEx matches from the provided regex when calling wp_embed_register_handler() .
$attrarrayrequired
Embed attributes.
$urlstringrequired
The original URL that was matched by the regex.
$rawattrarrayrequired
The original unmodified attributes.

Return

string The embed HTML.

Source

function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
	global $wp_embed;
	$embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) );

	/**
	 * Filters the YoutTube embed output.
	 *
	 * @since 4.0.0
	 *
	 * @see wp_embed_handler_youtube()
	 *
	 * @param string $embed   YouTube embed output.
	 * @param array  $attr    An array of embed attributes.
	 * @param string $url     The original URL that was matched by the regex.
	 * @param array  $rawattr The original unmodified attributes.
	 */
	return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
}

Hooks

apply_filters( ‘wp_embed_handler_youtube’, string $embed, array $attr, string $url, array $rawattr )

Filters the YoutTube embed output.

Changelog

VersionDescription
4.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.