Set About and Contact Page Types in Yoast Schema
Changes the WebPage type in the Yoast SEO graph to AboutPage, ContactPage or another type for the page slugs you choose.
Opens WPIDE on
Code
// Page slug => schema.org WebPage type.
$wpide_page_types = array(
'about' => 'AboutPage',
'contact' => 'ContactPage',
);
add_filter( 'wpseo_schema_webpage_type', function ( $type ) use ( $wpide_page_types ) {
if ( ! is_page() ) {
return $type;
}
$slug = get_post_field( 'post_name', get_queried_object_id() );
if ( isset( $wpide_page_types[ $slug ] ) ) {
// Keep WebPage alongside the subtype so Yoast's other pieces still match.
return array( 'WebPage', $wpide_page_types[ $slug ] );
}
return $type;
} );
Notes
Map your own page slugs to schema.org WebPage subtypes such as FAQPage, CollectionPage or CheckoutPage.
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.