Hello!
I just tested it, and annoyingly, LinkedIn prefers using oEmbed over Open Graph over Articles schema.
You have two options:
- Disable oEmbed (TSF has an option under Social Meta Settings > General > “Output oEmbed scripts?”). This might hamper some integrations and accessibility;
- Replace the oEmbed image with TSF’s social image (if present).
I’m not sure if I should make the second option a toggle in TSF. Nevertheless, this snippet should do the trick:
add_filter( 'oembed_response_data', [ $this, 'my_alter_oembed_response_data' ], 10, 4 );
/**
* @param array $data The response data.
* @param WP_Post $post The post object.
* @param int $width The requested width.
* @param int $height The calculated height.
* @return array Possibly altered $data.
*/
function my_alter_oembed_response_data( $data, $post, $width, $height ) {
if ( ! empty( $data['thumbnail_url'] ) ) {
$tsf = function_exists( 'the_seo_framework' ) ? the_seo_framework() : null;
if ( ! $tsf ) return $data;
$image_details = current( $tsf->get_image_details(
[
'id' => $post->ID,
'taxonomy' => '', // fill index to improve performance.
],
true, // Get single image
'embed', // context -- Don't use 'social', that'll enable fallback images.
true, // sanitize, get expected output
) );
if ( $image_details['url'] && $image_details['width'] && $image_details['height'] ) {
// Override WordPress provided data.
$data['thumbnail_url'] = $image_details['url'];
$data['thumbnail_width'] = $image_details['width'];
$data['thumbnail_height'] = $image_details['height'];
}
}
return $data;
}
I wasn’t too sure bout the conditionals–i.e., should we always include the thumbnail_url
, or only when there’s one set by WordPress?
Nevertheless, I hope this solves the issue you’re facing ?? Cheers!
-
This reply was modified 4 years, 7 months ago by
Sybre Waaijer. Reason: typos