WP_Sitemaps_Index::get_sitemap_list() WordPress Method

The WP_Sitemaps_Index::get_sitemap_list() method is used to get a list of all the sitemaps registered with the WordPress sitemap API. This can be useful for debugging purposes or for displaying a list of sitemaps on a WordPress site.

WP_Sitemaps_Index::get_sitemap_list() #

Gets a sitemap list for the index.


Return

(array[]) Array of all sitemaps.


Top ↑

Source

File: wp-includes/sitemaps/class-wp-sitemaps-index.php

	public function get_sitemap_list() {
		$sitemaps = array();

		$providers = $this->registry->get_providers();
		/* @var WP_Sitemaps_Provider $provider */
		foreach ( $providers as $name => $provider ) {
			$sitemap_entries = $provider->get_sitemap_entries();

			// Prevent issues with array_push and empty arrays on PHP < 7.3.
			if ( ! $sitemap_entries ) {
				continue;
			}

			// Using array_push is more efficient than array_merge in a loop.
			array_push( $sitemaps, ...$sitemap_entries );
			if ( count( $sitemaps ) >= $this->max_sitemaps ) {
				break;
			}
		}

		return array_slice( $sitemaps, 0, $this->max_sitemaps, true );
	}

Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.