Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.