# 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.

- Type: PHP
- Runs: Frontend only
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: aioseo, schema, news
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/aioseo-schema-news-article/

## Code

```php
// 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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Use NewsArticle Schema for a Category in All in One SEO" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
