Use NewsArticle Schema for a Category in All in One SEO
Changes Article and BlogPosting graphs in All in One SEO's schema to NewsArticle for posts in the categories you choose.
Opens WPIDE on
Code
// Category slugs whose posts are news.
$wpide_aioseo_news_cats = array( 'news' );
add_filter( 'aioseo_schema_output', function ( $graphs ) use ( $wpide_aioseo_news_cats ) {
if ( ! is_array( $graphs ) || ! is_singular( 'post' ) || ! has_category( $wpide_aioseo_news_cats, get_queried_object_id() ) ) {
return $graphs;
}
foreach ( $graphs as $i => $graph ) {
if ( isset( $graph['@type'] ) && in_array( $graph['@type'], array( 'Article', 'BlogPosting' ), true ) ) {
$graphs[ $i ]['@type'] = 'NewsArticle';
}
}
return $graphs;
} );
Notes
Use category slugs.
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.