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.
Opens WPIDE on
Code
// 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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.