all-in-one-seo-pack icon indicating copy to clipboard operation
all-in-one-seo-pack copied to clipboard

Apply Social Image settings to oEmbed

Open arnaudbroes opened this issue 3 years ago • 4 comments

@Kevin-Hamilton commented on Thu Mar 18 2021

Is your feature request related to a problem? Please describe. LinkedIn gives preference to oEmbed over og:image meta tags. The oEmbed "thumbnail_url" is taken from the featured image on the page rather than any social image setting made in AIOSEO.

Describe the solution you'd like I would like if the AIOSEO plugin could apply its social image settings to the oEmbed content in WordPress. If that is not possible, then at least an option to disable oEmbed (with appropriate warnings/disclaimers to the user), which would then force LinkedIn to fallback to og meta tags. My current workaround is to remove oEmbed by adding the following to the functions.php which in my testing does appear to get the job done:

remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
remove_action('wp_head', 'wp_oembed_add_host_js');

Additional context Related: https://wordpress.org/support/topic/linkedin-showing-wrong-image/

arnaudbroes avatar Mar 19 '21 13:03 arnaudbroes

@Kevin-Hamilton I accidentally moved instead of copied your issue to our internal repository so I've reopened it.

We're going to investigate this and see what our options are. Filtering the URL is more likely since removing those oEmbed discovery links and scripts may break a lot of other plugins.

arnaudbroes avatar Mar 19 '21 13:03 arnaudbroes

Thanks. I took a peek and it appears the oembed_response_data hook in wp-includes/embed.php would be the place to filter this. Will need to run with priority higher than 10 to override the result of the existing get_oembed_response_data_rich filter.

Kevin-Hamilton avatar Mar 23 '21 23:03 Kevin-Hamilton

@Kevin-Hamilton correct, I was thinking of doing something like this -

add_filter( 'oembed_response_data', [ $this, 'aioseo_filter_oembed_url' ], 10, 4 );

function aioseo_filter_oembed_url( $data, $post, $width, $height ) {
	if ( ! empty( $data['thumbnail_url'] ) ) {
			// Override URL, width and height here.
	}
	return $data;
}

Just need to get to it. Do you know when a oEmbed thumbnail URL is output in the source code (is it when you embed a YouTube video for example)? Knowing that, I can get this in one of the next updates significantly faster.

arnaudbroes avatar Mar 24 '21 09:03 arnaudbroes

It looks like the triggers for including the thumbnail_url in the oembed output are: if ( has_post_thumbnail( $post->ID ) ) or if ( 'attachment' === get_post_type( $post ) && wp_attachment_is_image( $post ) ) or if ( 'attachment' === get_post_type( $post ) && wp_attachment_is( 'video', $post ) )

I would think your criteria for setting it would not be limited to when it is already set, like your example code, but rather any post type where you would display an og:image.

Kevin-Hamilton avatar Mar 25 '21 02:03 Kevin-Hamilton