wp_embed_register_handler()WP 2.9.0

Registers an embed handler.

Should probably only be used for sites that do not support oEmbed.

No Hooks.


null. Nothing (null).


wp_embed_register_handler( $id, $regex, $callback, $priority );
$id(string) (required)
An internal ID/name for the handler. Needs to be unique.
$regex(string) (required)
The regex that will be used to see if this handler should be used for a URL.
$callback(callable) (required)
The callback function that will be called if the regex is matched.
Used to specify the order in which the registered handlers will be tested.
Default: 10



#1 Embedding gist in content posts

Do you want your gist link to turn directly into code the way WordPress converts a youtube video link directly into a player? Let's see how to do it below.

The example below works in both the visual editor and the block editor.

Use the following code by pasting it into functions.php or create a plugin:

add_action( 'init', 'register_gist_oembed_provider' );

function register_gist_oembed_provider() {


function callback_gist_oembed_provider( $matches ) {
	return sprintf( '<script src="%s.js"></script>', $matches[0] );

Since with this solution we don't make any queries on the backend, there is no caching of the result.


#2 Embed handler for Forbes video embedding


function wpdocs_embed_handler_forbes( $matches, $attr, $url, $rawattr ) {

	$src = add_query_arg(
			'show'   => (int) $matches['show'],
			'format' => 'frame',
			'width'  => (int) $matches['height'],
			'height' => (int) $matches['width'],
			'video'  => esc_attr( $matches['video'] ),
			'mode'   => 'render',

	$embed = strtr(
		'<iframe src="'. $src .'" width="{WIDTH}px" height="{HEIGHT}px" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>',
			'{HEIGHT}' => (int) $matches['height'],
			'{WIDTH}'  => (int) $matches['width'],

	return $embed;


  • Global. WP_Embed. $wp_embed


Since 2.9.0 Introduced.

wp_embed_register_handler() code WP 6.5.3

function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
	global $wp_embed;
	$wp_embed->register_handler( $id, $regex, $callback, $priority );