# Add Your Own Sitemaps to the Yoast Sitemap Index

> Lists extra sitemap files, such as one from a shop, forum or static section, in the Yoast SEO sitemap_index.xml so search engines find them in one place.

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

## Code

```php
// Full URLs of extra sitemap files.
$wpide_extra_sitemaps = array(
    home_url( '/shop-sitemap.xml' ),
    home_url( '/forum/sitemap.xml' ),
);

add_filter( 'wpseo_sitemap_index', function ( $xml ) use ( $wpide_extra_sitemaps ) {
    $lastmod = gmdate( 'c' );

    foreach ( $wpide_extra_sitemaps as $url ) {
        $xml .= "<sitemap>\n\t<loc>" . esc_url( $url ) . "</loc>\n\t<lastmod>" . esc_html( $lastmod ) . "</lastmod>\n</sitemap>\n";
    }

    return $xml;
} );
```

## Notes

Use full URLs on your own domain; search engines ignore cross-site sitemaps without verification.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Add Your Own Sitemaps to the Yoast Sitemap Index" 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/
