embed_cache_oembed_types WordPress Filter Hook
The embed_cache_oembed_types hook is used to filter the list of oEmbed providers that are cached by the WordPress oEmbed handler. This hook is useful for sites that want to cache oEmbed responses from specific providers. For example, a site may want to cache oEmbed responses from YouTube, but not from Vimeo. The hook takes two arguments: $providers and $post_id. $providers is an array of oEmbed provider URLs. $post_id is the post ID of the post being embedded. The hook can be used like this: function my_embed_cache_oembed_types( $providers, $post_id ) { // Only cache oEmbed responses from YouTube. if ( in_array( 'https://www.youtube.com/oembed', $providers ) ) { return array( 'https://www.youtube.com/oembed' ); } // Don't cache any oEmbed responses. return array(); } add_filter( 'embed_cache_oembed_types', 'my_embed_cache_oembed_types', 10, 2 );
apply_filters( 'embed_cache_oembed_types', string[] $post_types ) #
Filters the array of post types to cache oEmbed results for.
Parameters
- $post_types
(string[])Array of post type names to cache oEmbed results for. Defaults to post types with
show_ui
set to true.
Source
Changelog
Version | Description |
---|---|
2.9.0 | Introduced. |