wp_embed_handler_youtube
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.
Returns (string)
The embed HTML.
Parameters (4)
- 0. $matches (array)
- The RegEx matches from the provided regex when calling
wp_embed_register_handler(…)
. - 1. $attr (array)
- Embed attributes.
- 2. $url (string)
- The original URL that was matched by the regex.
- 3. $rawattr (array)
- The original unmodified attributes.
Usage
if ( !function_exists( 'wp_embed_handler_youtube' ) ) { require_once ABSPATH . WPINC . '/embed.php'; } // The RegEx matches from the provided regex when calling // wp_embed_register_handler(). $matches = array(); // Embed attributes. $attr = array(); // The original URL that was matched by the regex. $url = ''; // The original unmodified attributes. $rawattr = array(); // NOTICE! Understand what this does before running. $result = wp_embed_handler_youtube($matches, $attr, $url, $rawattr);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/embed.php
- function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
- global $wp_embed;
- $embed = $wp_embed->autoembed( "https://youtube.com/watch?v={$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 );
- }