Site icon Hip-Hop Website Design and Development

Set og:image programmatically in custom single post with external images

I have created a plugin with a custom post type and the single post template pulls in photos from an external site. I would like to programmatically set the source for one of these images as the og:image meta data in the page header. At the moment, it is defaulting to the sites default image.

The gallery of images is retrieved using an ajax call from the single post template. I would like to set the meta tag value based on the first image returned.

The single post template calls get_header() so the header is already built before the gallery is returned. So I need a means to replace or override the one entry in the header. Everything else in the header is as I would like it but that is all based on static data set at the time the post is created/edited.

I am not even sure what I am trying to achieve is possible but would be extremely grateful if anyone has any useful ideas.