WP_Sitemaps::render_sitemaps()
Renders sitemap templates based on rewrite rules.
Method of the class: WP_Sitemaps{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WP_Sitemaps = new WP_Sitemaps(); $WP_Sitemaps->render_sitemaps();
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
Since 5.5.0 | Introduced. |
WP_Sitemaps::render_sitemaps() WP Sitemaps::render sitemaps code WP 6.6.2
public function render_sitemaps() { global $wp_query; $sitemap = sanitize_text_field( get_query_var( 'sitemap' ) ); $object_subtype = sanitize_text_field( get_query_var( 'sitemap-subtype' ) ); $stylesheet_type = sanitize_text_field( get_query_var( 'sitemap-stylesheet' ) ); $paged = absint( get_query_var( 'paged' ) ); // Bail early if this isn't a sitemap or stylesheet route. if ( ! ( $sitemap || $stylesheet_type ) ) { return; } if ( ! $this->sitemaps_enabled() ) { $wp_query->set_404(); status_header( 404 ); return; } // Render stylesheet if this is stylesheet route. if ( $stylesheet_type ) { $stylesheet = new WP_Sitemaps_Stylesheet(); $stylesheet->render_stylesheet( $stylesheet_type ); exit; } // Render the index. if ( 'index' === $sitemap ) { $sitemap_list = $this->index->get_sitemap_list(); $this->renderer->render_index( $sitemap_list ); exit; } $provider = $this->registry->get_provider( $sitemap ); if ( ! $provider ) { return; } if ( empty( $paged ) ) { $paged = 1; } $url_list = $provider->get_url_list( $paged, $object_subtype ); // Force a 404 and bail early if no URLs are present. if ( empty( $url_list ) ) { $wp_query->set_404(); status_header( 404 ); return; } $this->renderer->render_sitemap( $url_list ); exit; }