Skip to content

Instantly share code, notes, and snippets.

@dmje
Created November 20, 2025 10:04
Show Gist options
  • Select an option

  • Save dmje/5e69a74a0ffb043c8f1a17dec2df8a55 to your computer and use it in GitHub Desktop.

Select an option

Save dmje/5e69a74a0ffb043c8f1a17dec2df8a55 to your computer and use it in GitHub Desktop.
This one seems to work. Example deployed to MoDA on 24/09/20. See link to Gist below for other examples.
<?php
// Change OG image for single objects
// Based on snippet here https://gist.github.com/amboutwe/811e92b11e5277977047d44ea81ee9d4
add_filter( 'wpseo_opengraph_image', 'change_opengraph_image_url' );
function change_opengraph_image_url( $url )
{
if(is_singular( 'object' ))
{
$seo_image = cos_get_field('image');
$seo_image = str_replace('v0_web.jpg', 'v0_high.jpg', $seo_image);
return $seo_image;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment