There is a filter you can use to override the markup output, I would use that to solve this issue, here is an example of code that you can customize to grab the image from a post meta field:
function schema_wp_set_default_image_12345( $json ) {
// If image is already defiend,
// return our $json array and do not do anything
if ( isset($json['media']) && ! empty($json['media']) ) return $json;
// There is no image defined in Schema array,
// set default ImageObject url, width, and height
$json['media']['@type'] = 'ImageObject'; // schema type, do not chage this!
$json['media']['url'] = 'http://default-image-url.png'; // set default image url
$json['media']['width'] = 720; // set image width
$json['media']['height'] = 400; // set image height
return $json;
}
add_filter('schema_json', 'schema_wp_set_default_image_12345');
Here is a link to the code gist.
I hope this helps.
Thread Starter
omma46
(@omma46)
Thanks for the reply.
This solves the immidiate problem, however it will use the same image for all pages/posts. If there was a custom field for markup, similar to heading and description, i could choose a unique image for every page/post.
Hi @omma46.
I’d like to be able to selectively override the image for pages/posts.
Did you ever manage to add a custom field for images?
Thanks
Tim