WP_Sitemaps_Provider::get_sitemap_url() WordPress Method

The WP_Sitemaps_Provider::get_sitemap_url() method is used to get the URL for a sitemap. This is useful for generating a sitemap for a website.

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

Gets the URL of a sitemap entry.


Parameters

$name

(string)(Required)The name of the sitemap.

$page

(int)(Required)The page of the sitemap.


Top ↑

Return

(string) The composed URL for a sitemap entry.


Top ↑

Source

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

	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 );
	}


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.