# rel="prev" and rel="next" Links on Paginated Archives

> Adds rel prev and next link tags to paginated blog, category and archive pages, which Bing and other crawlers use to understand page series.

- Type: PHP
- Runs: Frontend only
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: pagination, archives, crawling
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/seo-rel-prev-next/

## Code

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

    if ( is_singular() || is_404() || ! ( is_home() || is_archive() || is_search() ) ) {
        return;
    }

    $paged = max( 1, (int) get_query_var( 'paged' ) );
    $max   = (int) $wp_query->max_num_pages;

    if ( $paged > 1 ) {
        echo '<link rel="prev" href="' . esc_url( get_pagenum_link( $paged - 1 ) ) . '">' . "\n";
    }

    if ( $paged < $max ) {
        echo '<link rel="next" href="' . esc_url( get_pagenum_link( $paged + 1 ) ) . '">' . "\n";
    }
} );
```

## Notes

Skip this if your SEO plugin already prints these links.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "rel="prev" and rel="next" Links on Paginated Archives" 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/
