Registers an embed handler.
Description
Should probably only be used for sites that do not support oEmbed.
Parameters
$id
stringrequired- An internal ID/name for the handler. Needs to be unique.
$regex
stringrequired- The regex that will be used to see if this handler should be used for a URL.
$callback
callablerequired- The callback function that will be called if the regex is matched.
$priority
intoptional- Used to specify the order in which the registered handlers will be tested.
Default:
10
Source
function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
global $wp_embed;
$wp_embed->register_handler( $id, $regex, $callback, $priority );
}
Changelog
Version | Description |
---|---|
2.9.0 | Introduced. |
Basic Example
Register an embed handler for Forbes video embeds.
Here is a means to add oembed support for web-based audio recorders Vocaroo and Sodaphonic. I found the hard way that sprintf fails when you have a “%” in the string
Note that the
$regex
parameter is checked against the URL, not against the content, so you can anchor the regular expression with^
and$
. This is useful if you want to use an ungreedy match group at the end of your URL: