WP_Sitemaps_Provider::get_sitemap_url()
Gets the URL of a sitemap entry.
Method of the class: WP_Sitemaps_Provider{}
No Hooks.
Return
String
. The composed URL for a sitemap entry.
Usage
$WP_Sitemaps_Provider = new WP_Sitemaps_Provider(); $WP_Sitemaps_Provider->get_sitemap_url( $name, $page );
- $name(string) (required)
- The name of the sitemap.
- $page(int) (required)
- The page of the sitemap.
Notes
- Global. WP_Rewrite. $wp_rewrite WordPress rewrite component.
Changelog
Since 5.5.0 | Introduced. |
WP_Sitemaps_Provider::get_sitemap_url() WP Sitemaps Provider::get sitemap url code WP 6.6.2
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 ); }