WP_Sitemaps_Provider::get_sitemap_url( string $name, int $page ): string

In this article

Gets the URL of a sitemap entry.

Parameters

$namestringrequired
The name of the sitemap.
$pageintrequired
The page of the sitemap.

Return

string The composed URL for a sitemap entry.

Source

public function get_sitemap_url( $name, $page ) {
	global $wp_rewrite;

	// Accounts for cases where name is not included, ex: sitemaps-users-1.xml.
	$params = array_filter(
		array(
			'sitemap'         => $this->name,
			'sitemap-subtype' => $name,
			'paged'           => $page,
		)
	);

	$basename = sprintf(
		'/wp-sitemap-%1$s.xml',
		implode( '-', $params )
	);

	if ( ! $wp_rewrite->using_permalinks() ) {
		$basename = '/?' . http_build_query( $params, '', '&' );
	}

	return home_url( $basename );
}

Changelog

VersionDescription
5.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.