I would like to set individual facebook open graph meta images (og:image
) for specific posts in Wordpress.
For example, set og:image
to cat_1_image.jpg
if the post is in category 1, and set it to cat_2_image.jpg
if the post is in category with id = 2.
Pseudo-Code:
if($category->term_id == 1)
og:image = 'cat_1_image.jpg';
elseif($category->term_id == 2)
og:image = 'cat_2_image.jpg';
elseif($category->term_id == 3) // CatID 3 means 'Post has images, no default og:image, please'
og:image = '';
Now, I've looked at the various hooks of wpseo, like wpseo_pre_analysis_post_content
and wpseo_opengraph_image
but this does not seem to lead in the right direction.
Can anybody please explain to me how to achieve different og:images for different post categories?!
The reason for my hack: WP SEO does not pick up images which are inserted into a post using the gallery shortcode. It will fall back to include the default image (as specified under WP SEO options) as the og:image. Hence I want to disable the inclusion of the default image for posts of a certain category (i.e. category 'has_images') and let the facebook scraper pick up the gallery images - they DO get picked up if no default og:image is present!