WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp embed register handler

Description

Register an embed handler. If the site in question supports oEmbed, consider using wp_oembed_add_provider() instead. See the Embeds document for more details.

This function should be called from a plugin or a theme's functions.php file.

Usage

 <?php wp_embed_register_handler$id$regex$callback$priority ); ?> 

Parameters

$id
(string) (required) An internal ID/name for the handler. Needs to be unique.
Default: None
$regex
(string) (required) The regex that will be used to see if this handler should be used for a URL.
Default: None
$callback
(callback) (required) The callback function that will be called if the regex is matched.
Default: None
$priority
(int) (optional) Used to specify the order in which the registered handlers will be tested (default: 10). Lower numbers correspond with earlier testing, and handlers with the same priority are tested in the order in which they were added to the action.
Default: 10

Examples

Register an embed handler for Forbes video embeds.

<?php

wp_embed_register_handler( 'forbes', '#http://(?:www|video)\.forbes\.com/(?:video/embed/embed\.html|embedvideo/)\?show=([\d]+)&format=frame&height=([\d]+)&width=([\d]+)&video=(.+?)($|&)#i', 'wp_embed_handler_forbes' );

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

	$embed = sprintf(
			'<iframe src="http://www.forbes.com/video/embed/embed.html?show=%1$s&format=frame&height=%2$s&width=%3$s&video=%4$s&mode=render" width="%3$spx" height="%2$spx" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>',
			esc_attr($matches[1]),
			esc_attr($matches[2]),
			esc_attr($matches[3]),
			esc_attr($matches[4])
			);

	return apply_filters( 'embed_forbes', $embed, $matches, $attr, $url, $rawattr );
}

?>

Change Log

Since: 2.9.0

Related

Embeds: wp_oembed_add_provider(), wp_oembed_remove_provider(), wp_oembed_get(), wp_embed_defaults(), wp_embed_register_handler(), wp_embed_unregister_handler(), get_embedded_audio(), get_embedded_media(), get_embedded_video(), wp_embed_handler_audio(), wp_embed_handler_video()