# Set the Open Graph Type for a Post Type in Yoast

> Changes the og:type Yoast SEO outputs for a custom post type, for example "article" for a news or recipe post type that Yoast marks as a website.

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

## Code

```php
// Post type => og:type.
$wpide_og_types = array(
    'recipe' => 'article',
    'news'   => 'article',
);

add_filter( 'wpseo_opengraph_type', function ( $type ) use ( $wpide_og_types ) {
    if ( is_singular( array_keys( $wpide_og_types ) ) ) {
        return $wpide_og_types[ get_post_type( get_queried_object_id() ) ];
    }

    return $type;
} );
```

## Notes

Facebook accepts website, article, profile, book and the video and music types.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Set the Open Graph Type for a 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/
