# ItemList Structured Data on Archive Pages

> Adds ItemList JSON-LD listing the posts shown on category, tag, post type and blog archive pages, using the posts already loaded so it adds no queries.

- Type: PHP
- Runs: Frontend only
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: schema, archives, json-ld
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/seo-itemlist-archive-schema/

## Code

```php
add_action( 'wp_head', function () {
    global $wp_query;

    if ( ! ( is_home() || is_category() || is_tag() || is_tax() || is_post_type_archive() ) || empty( $wp_query->posts ) ) {
        return;
    }

    $offset = ( max( 1, (int) get_query_var( 'paged' ) ) - 1 ) * (int) $wp_query->get( 'posts_per_page' );
    $items  = array();

    foreach ( $wp_query->posts as $i => $post ) {
        $items[] = array( '@type' => 'ListItem', 'position' => $offset + $i + 1, 'url' => get_permalink( $post ) );
    }

    echo '<script type="application/ld+json">' . wp_json_encode( array( '@context' => 'https://schema.org', '@type' => 'ItemList', 'itemListElement' => $items ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG ) . "</script>\n";
} );
```

## Notes

Google uses ItemList for carousels of some content types, such as recipes and courses.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "ItemList Structured Data on Archive Pages" 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/
