# Add Custom URLs to the XML Sitemap

> Adds a sitemap of extra URLs, such as static landing pages or sections served outside WordPress, to the built-in sitemap index.

- Type: PHP
- Runs: Run everywhere
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: sitemap, xml, custom-urls
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/extra-urls-sitemap/

## Code

```php
// Extra URLs to include.
$wpide_extra_sitemap_urls = array(
    home_url( '/landing/spring-offer/' ),
    home_url( '/docs/' ),
);

add_action( 'init', function () use ( $wpide_extra_sitemap_urls ) {
    if ( ! class_exists( 'WP_Sitemaps_Provider' ) || ! wp_sitemaps_get_server()->sitemaps_enabled() ) {
        return;
    }

    if ( ! class_exists( 'WPIDE_Extra_Urls_Sitemap' ) ) {
        class WPIDE_Extra_Urls_Sitemap extends WP_Sitemaps_Provider {
            protected $urls = array();

            public function __construct( array $urls ) {
                $this->name        = 'extra';
                $this->object_type = 'extra';
                $this->urls        = $urls;
            }

            public function get_url_list( $page_num, $object_subtype = '' ) {
                return array_map( function ( $url ) {
                    return array( 'loc' => esc_url_raw( $url ) );
                }, $this->urls );
            }

            public function get_max_num_pages( $object_subtype = '' ) {
                return $this->urls ? 1 : 0;
            }
        }
    }

    wp_register_sitemap_provider( 'extra', new WPIDE_Extra_Urls_Sitemap( $wpide_extra_sitemap_urls ) );
}, 20 );
```

## Notes

List full URLs on your own domain. The new sitemap appears at /wp-sitemap-extra-1.xml and in /wp-sitemap.xml.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Add Custom URLs to the XML Sitemap" 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/
