WP_Sitemaps_Stylesheet::get_sitemap_index_stylesheet()publicWP 5.5.0

Returns the escaped XSL for the index sitemaps.

Method of the class: WP_Sitemaps_Stylesheet{}

Hooks from the method

Return

null. Nothing (null).

Usage

$WP_Sitemaps_Stylesheet = new WP_Sitemaps_Stylesheet();
$WP_Sitemaps_Stylesheet->get_sitemap_index_stylesheet();

Changelog

Since 5.5.0 Introduced.

WP_Sitemaps_Stylesheet::get_sitemap_index_stylesheet() code WP 6.5.2

public function get_sitemap_index_stylesheet() {
	$css         = $this->get_stylesheet_css();
	$title       = esc_xml( __( 'XML Sitemap' ) );
	$description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) );
	$learn_more  = sprintf(
		'<a href="%s">%s</a>',
		esc_url( __( 'https://www.sitemaps.org/' ) ),
		esc_xml( __( 'Learn more about XML sitemaps.' ) )
	);

	$text = sprintf(
		/* translators: %s: Number of URLs. */
		esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ),
		'<xsl:value-of select="count( sitemap:sitemapindex/sitemap:sitemap )" />'
	);

	$lang    = get_language_attributes( 'html' );
	$url     = esc_xml( __( 'URL' ) );
	$lastmod = esc_xml( __( 'Last Modified' ) );

	$xsl_content = <<<XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
	exclude-result-prefixes="sitemap"
	>

<xsl:output method="html" encoding="UTF-8" indent="yes" />

<!--
  Set variables for whether lastmod occurs for any sitemap in the index.
  We do this up front because it can be expensive in a large sitemap.
  -->
<xsl:variable name="has-lastmod" select="count( /sitemap:sitemapindex/sitemap:sitemap/sitemap:lastmod )" />

<xsl:template match="/">
	<html {$lang}>
		<head>
			<title>{$title}</title>
			<style>
				{$css}
			</style>
		</head>
		<body>
			<div id="sitemap">
				<div id="sitemap__header">
					<h1>{$title}</h1>
					<p>{$description}</p>
					<p>{$learn_more}</p>
				</div>
				<div id="sitemap__content">
					<p class="text">{$text}</p>
					<table id="sitemap__table">
						<thead>
							<tr>
								<th class="loc">{$url}</th>
								<xsl:if test="\$has-lastmod">
									<th class="lastmod">{$lastmod}</th>
								</xsl:if>
							</tr>
						</thead>
						<tbody>
							<xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
								<tr>
									<td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td>
									<xsl:if test="\$has-lastmod">
										<td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td>
									</xsl:if>
								</tr>
							</xsl:for-each>
						</tbody>
					</table>
				</div>
			</div>
		</body>
	</html>
</xsl:template>
</xsl:stylesheet>

XSL;

	/**
	 * Filters the content of the sitemap index stylesheet.
	 *
	 * @since 5.5.0
	 *
	 * @param string $xsl_content Full content for the XML stylesheet.
	 */
	return apply_filters( 'wp_sitemaps_stylesheet_index_content', $xsl_content );
}