# Default Social Image per Post Type in Yoast

> Gives Yoast SEO a fallback Open Graph image for each post type when a post has neither a social image nor a featured image.

- Type: PHP
- Runs: Frontend only
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: yoast, open-graph, images
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/yoast-og-image-fallback-post-type/

## Code

```php
// Post type => fallback image URL.
$wpide_og_fallbacks = array(
    'post'    => home_url( '/wp-content/uploads/social-blog.jpg' ),
    'product' => home_url( '/wp-content/uploads/social-shop.jpg' ),
);

add_filter( 'wpseo_opengraph_image', function ( $image ) use ( $wpide_og_fallbacks ) {
    if ( $image || ! is_singular( array_keys( $wpide_og_fallbacks ) ) ) {
        return $image;
    }

    return $wpide_og_fallbacks[ get_post_type( get_queried_object_id() ) ];
} );
```

## Notes

Use images at least 1200 × 630 pixels. Yoast's site-wide default image still applies to other types.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Default Social Image per Post Type in Yoast" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
