• Resolved rmlumley

    (@rmlumley)


    I have a custom field I’m using that pulls in an Image I’d like to use as the OG:image. Is there a way to automatically set this as the OG:image?

    Or – related – can I set the Featured Image built into WordPress to set to the value of this custom field.

    Essentially, I’m trying to find a way that won’t result in me editing all my existing posts and setting the Open Graph Image Custom Field to an image that is already in a Custom Field.

    https://www.ads-software.com/plugins/wonderm00ns-simple-facebook-open-graph-tags/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I too would like to know this…

    You can use the “fb_og_image” filter that our plugin provides.

    You do not need to copy the value from your custom field to our custom field, you just need to use the filter.

    Something like this:

    add_filter('fb_og_image', 'my_custom_fb_og_image');
    function my_custom_fb_og_image($fb_image) {
    	global $post;
    	if ($custom_image=get_post_meta($post->ID, 'your_custom_field', true)) {
    		if (trim($custom_image)!='') $fb_image=trim($custom_image);
    	}
    	return $fb_image;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set og:image to custom field’ is closed to new replies.