Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Social Image settings to oEmbed #3186

Open
arnaudbroes opened this issue Mar 19, 2021 · 4 comments
Open

Apply Social Image settings to oEmbed #3186

arnaudbroes opened this issue Mar 19, 2021 · 4 comments

Comments

@arnaudbroes
Copy link
Contributor

arnaudbroes commented Mar 19, 2021

@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
Copy link
Contributor Author

@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.

@Kevin-Hamilton
Copy link

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.

@arnaudbroes
Copy link
Contributor Author

arnaudbroes commented Mar 24, 2021

@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.

@Kevin-Hamilton
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants