WordPress at Your Fingertips
function is not described

WP_Sitemaps::redirect_sitemapxml() public WP 5.5.0

Redirects a URL to the wp-sitemap.xml

{} It's a method of the class: WP_Sitemaps{}

No Hooks.


true|false. Bypass value.


$WP_Sitemaps = new WP_Sitemaps();
$WP_Sitemaps->redirect_sitemapxml( $bypass, $query );
$bypass(true|false) (required)
Pass-through of the pre_handle_404 filter value.
$query(WP_Query) (required)
The WP_Query object.


Since 5.5.0 Introduced.

Code of WP_Sitemaps::redirect_sitemapxml() WP 5.7.2

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

	return $bypass;