wp_embed_handler_youtube

YouTube iframe embed handler callback.

Description

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

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

  1. if ( !function_exists( 'wp_embed_handler_youtube' ) ) { 
  2. require_once ABSPATH . WPINC . '/embed.php'; 
  3.  
  4. // The RegEx matches from the provided regex when calling 
  5. // wp_embed_register_handler(). 
  6. $matches = array(); 
  7.  
  8. // Embed attributes. 
  9. $attr = array(); 
  10.  
  11. // The original URL that was matched by the regex. 
  12. $url = ''; 
  13.  
  14. // The original unmodified attributes. 
  15. $rawattr = array(); 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = wp_embed_handler_youtube($matches, $attr, $url, $rawattr); 
  19.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/embed.php  
  1. function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) { 
  2. global $wp_embed; 
  3. $embed = $wp_embed->autoembed( sprintf( "https://youtube.com/watch?v=%s", urlencode( $matches[2] ) ) ); 
  4.  
  5. /** 
  6. * Filters the YoutTube embed output. 
  7. * @since 4.0.0 
  8. * @see wp_embed_handler_youtube() 
  9. * @param string $embed YouTube embed output. 
  10. * @param array $attr An array of embed attributes. 
  11. * @param string $url The original URL that was matched by the regex. 
  12. * @param array $rawattr The original unmodified attributes. 
  13. */ 
  14. return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );