wp_oembed_add_provider()WP 2.9.0

Adds a URL format and oEmbed provider URL pair.

No Hooks.

Return

null. Nothing (null).

Usage

wp_oembed_add_provider( $format, $provider, $regex );
$format(string) (required)
The format of URL that this provider can handle. You can use asterisks as wildcards.
$provider(string) (required)
The URL to the oEmbed provider.
$regex(true|false)
Whether the $format parameter is in a RegEx format.
Default: false

Examples

0

#1 Example of adding a provider

Suppose we need to add oEmbed embedding for website wizer.me and we found out that this website is an oEmbed provider and found such data to handle such request:

  • URL scheme: http://*.wizer.me/learn/*
  • URL scheme: https://*.wizer.me/learn/*
  • URL scheme: http://*.wizer.me/preview/*
  • URL scheme: https://*.wizer.me/preview/*
  • API endpoint: http://app.wizer.me/api/oembed.{format}
  • Supports discovery via <link> tags
// Add an embedding for wizer.me
add_action( 'init', 'wizerme_oembed_provider' );

function wizerme_oembed_provider() {
	wp_oembed_add_provider( 'http://*.wizer.me/learn/*', 'http://app.wizer.me/api/oembed.{format}', false );
	wp_oembed_add_provider( 'https://*.wizer.me/learn/*', 'http://app.wizer.me/api/oembed.{format}', false );

	wp_oembed_add_provider( 'http://*.wizer.me/preview/*', 'http://app.wizer.me/api/oembed.{format}', false );
	wp_oembed_add_provider( 'https://*.wizer.me/preview/*', 'http://app.wizer.me/api/oembed.{format}', false );
}

Now when you insert a link like https://app.wizer.me/preview/1J09IV into the content, it will be processed and embedded in the content as an iframe.

0

#2 Example of adding a provider

The format here specifies a regular expression.

!!! This is just a demonstration, in fact, youtube provider is already registered in WordPress.

add_action( 'init', 'youtube_oembed_provider' );

function youtube_oembed_provider() {
	wp_oembed_add_provider( '#https?://youtu\.be/.*#i', 'https://www.youtube.com/oembed', true );
}
0

#3 Examples of adding providers from the kernel

See code of the WP_oEmbed::__construct() method.

Notes

Changelog

Since 2.9.0 Introduced.

wp_oembed_add_provider() code WP 6.5.2

function wp_oembed_add_provider( $format, $provider, $regex = false ) {
	if ( did_action( 'plugins_loaded' ) ) {
		$oembed                       = _wp_oembed_get_object();
		$oembed->providers[ $format ] = array( $provider, $regex );
	} else {
		WP_oEmbed::_add_provider_early( $format, $provider, $regex );
	}
}