The oembed_response_data WordPress PHP filter allows you to modify the oEmbed response data.
Usage
add_filter('oembed_response_data', 'your_custom_function', 10, 4); function your_custom_function($data, $post, $width, $height) { // your custom code here return $data; }
Parameters
$data
(array) – The oEmbed response data.$post
(WP_Post) – The post object.$width
(int) – The requested width.$height
(int) – The calculated height.
More information
See WordPress Developer Resources: oembed_response_data
Examples
Modify oEmbed Thumbnail URL
Change the thumbnail URL in the oEmbed response.
add_filter('oembed_response_data', 'modify_thumbnail_url', 10, 4); function modify_thumbnail_url($data, $post, $width, $height) { $data['thumbnail_url'] = 'https://your-custom-url.com/thumbnail.jpg'; return $data; }
Add Custom Field to oEmbed Data
Add a custom field value to the oEmbed response data.
add_filter('oembed_response_data', 'add_custom_field_to_oembed', 10, 4); function add_custom_field_to_oembed($data, $post, $width, $height) { $custom_field = get_post_meta($post->ID, 'your_custom_field', true); $data['custom_field'] = $custom_field; return $data; }
Modify oEmbed Title
Change the title in the oEmbed response.
add_filter('oembed_response_data', 'modify_oembed_title', 10, 4); function modify_oembed_title($data, $post, $width, $height) { $data['title'] = 'New Title: ' . $data['title']; return $data; }
Remove Author Name from oEmbed Data
Remove the author name from the oEmbed response data.
add_filter('oembed_response_data', 'remove_author_from_oembed', 10, 4); function remove_author_from_oembed($data, $post, $width, $height) { unset($data['author_name']); return $data; }
Set a Maximum Width for oEmbed
Limit the maximum width of the oEmbed content.
add_filter('oembed_response_data', 'limit_oembed_width', 10, 4); function limit_oembed_width($data, $post, $width, $height) { $max_width = 500; if ($width > $max_width) { $data['width'] = $max_width; } return $data; }