embed_oembed_discover
Allows you to specify whether WordPress should visit a URL and look for an embeddability <link> tag on the remote site.
Allows you to change the $attr['discover'] attribute for wp_oembed_get( $url, $args ).
When a site is an oEmbed provider, it indicates this in the HTML document's <head> section. Example tags:
<link rel="alternate" type="application/json+oembed" href="/api/oembed/1.0/embed?url=https%3A%2F%2Fwp-kama.ru%2Fhandbook%2Fcodex%2Foembed" /> <link rel="alternate" type="text/xml+oembed" href="/api/oembed/1.0/embed?url=https%3A%2F%2Fwp-kama.ru%2Fhandbook%2Fcodex%2Foembed&format=xml" />
In other words, every oEmbed provider should have tags like these to announce that the current page can be embedded on another site.
When a URL is added to site content, WordPress checks whether it belongs to a registered oEmbed provider such as YouTube. If it does, the embed code is generated using the known logic for that URL. Otherwise, WordPress can visit the URL and inspect its HTML for tags indicating that it can be embedded.
This hook enables or disables that HTML tag discovery. Returning false prevents the check for unknown URLs. Therefore, when content contains a URL unknown to WordPress, it is not inspected and is simply displayed as-is.
See also oEmbed in WordPress.
Usage
add_filter( 'embed_oembed_discover', 'wp_kama_embed_oembed_discover_filter' );
/**
* Function for `embed_oembed_discover` filter-hook.
*
* @param bool $enable Whether to enable `<link>` tag discovery.
*
* @return bool
*/
function wp_kama_embed_oembed_discover_filter( $enable ){
// filter...
return $enable;
}
- $enable(true|false)
- Whether to enable discovery of the
<link>tag at the URL.
Default: true
Examples
#1 Disable oEmbed auto-discovery for unknown URLs
// Remove oEmbed iframes communication JavaScript from the front end and back end. remove_action( 'wp_head', 'wp_oembed_add_host_js' ); // Turn off the oEmbed auto-discovery request for unknown URLs. add_filter( 'embed_oembed_discover', '__return_false' );
Changelog
| Since 2.9.0 | Introduced. |
| Since 4.4.0 | The default value changed to true. |
Where the hook is called
$attr['discover'] = apply_filters( 'embed_oembed_discover', true );