Ren Stanforth

Software Engineer

Ren Stanforth

Software Engineer

Menu
Blog Post

Add Article Schema to Custom Post Types in WP for Yoast SEO

February 6, 2025 Tutorials
Add Article Schema to Custom Post Types in WP for Yoast SEO

Hi fellow WordPress enthusiasts! If you’re looking to sprinkle some SEO magic on your custom post types using Yoast SEO, you’ve come to the right place. Today, we’re diving into the world of Article schema—because who doesn’t want their content to be the star of the search engine show?

Benefits of Adding Article Schema to Custom Post Types

Article schema is like a backstage pass for search engines, giving them a VIP tour of your content. By default, Yoast SEO rolls out the red carpet for standard post types, but with a little tweak, you can extend this privilege to your custom post types too. Let’s get started!

How to Add Article Schema to Custom Post Types

1. Add Article Schema to Your Custom Post Type

First up, let’s teach Yoast SEO to recognize your custom post type, like ‘book’, as worthy of Article schema. Here’s a nifty function to do just that:

/**
 * Add 'book' to the list of articles post types, so books get Article schema.
 *
 * @param  mixed $post_types The current list of post types.
 *
 * @return array Array of post types for which Yoast SEO renders Article schema.
 */
function article_schema_for_books( $post_types ) {
    $post_types[] = 'book';
    return $post_types;
}

add_filter( 'wpseo_schema_article_post_types', 'article_schema_for_books' );

This little snippet hooks into the wpseo_schema_article_post_types filter, adding ‘book’ to the list of post types that will strut their stuff with Article schema.

2. Ensure Your Post Type Supports an Author

Now, here’s the part that often gets overlooked—like forgetting to add salt to your soup. For the Article schema to work its magic, your custom post type needs to support an author. Add this line to make sure your ‘book’ post type is author-friendly:

add_post_type_support( 'book', 'author' );

Important Note

Currently, this method doesn’t work for the ‘page‘ post type. But don’t worry, the Yoast team is on it—like a cat on a laser pointer.

Conclusion

And there you have it! With these steps, your custom post types can bask in the SEO spotlight, thanks to Article schema. By adding Article Schema to your custom post types, you enhance your site’s SEO and visibility. Keep an eye out for updates from Yoast, as they’re always working to make their plugin even more awesome.


Feel free to reach out if you have any questions or need further assistance. Until next time, may your code be clean and your rankings high!

Write a comment