WP_Sitemaps::redirect_sitemapxml() WordPress Method

The WP_Sitemaps::redirect_sitemapxml() method is used to redirect the user to the sitemap XML file. This is useful if you want to make sure that the user always gets the latest version of the sitemap XML file.

WP_Sitemaps::redirect_sitemapxml( bool $bypass, WP_Query $query ) #

Redirects a URL to the wp-sitemap.xml


Parameters

$bypass

(bool)(Required)Pass-through of the pre_handle_404 filter value.

$query

(WP_Query)(Required)The WP_Query object.


Top ↑

Return

(bool) Bypass value.


Top ↑

Source

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

	public function redirect_sitemapxml( $bypass, $query ) {
		// If a plugin has already utilized the pre_handle_404 function, return without action to avoid conflicts.
		if ( $bypass ) {
			return $bypass;
		}

		// 'pagename' is for most permalink types, name is for when the %postname% is used as a top-level field.
		if ( 'sitemap-xml' === $query->get( 'pagename' )
			|| 'sitemap-xml' === $query->get( 'name' )
		) {
			wp_safe_redirect( $this->index->get_index_url() );
			exit();
		}

		return $bypass;
	}


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.