Skip to content

Instantly share code, notes, and snippets.

@websupporter
Last active February 1, 2022 15:36
Show Gist options
  • Save websupporter/384face6ae26700fb280 to your computer and use it in GitHub Desktop.
Save websupporter/384face6ae26700fb280 to your computer and use it in GitHub Desktop.
Change the oEmbed output of WordPress
<?php
add_filter( 'oembed_response_data', 'fwe_oembed_response_data', 11, 4 );
function fwe_oembed_response_data( $data, $post, $width, $height ){
if ( ! is_object( $post ) )
return $data;
if( ! has_post_thumbnail( $post->ID ) )
return $data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $thumbnail_id, 'full' );
$data = array(
'version' => '1.0',
'provider_name' => get_bloginfo( 'name' ),
'provider_url' => get_home_url(),
'author_name' => get_bloginfo( 'name' ),
'author_url' => get_home_url(),
'title' => $post->post_title,
'type' => 'photo',
'url' => $image[0],
'width' => $image[1],
'height' => $image[2],
);
return $data;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment